Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ docs/

/neardev/dev-account
/neardev/dev-account.env

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
768 changes: 768 additions & 0 deletions .yarn/releases/yarn-3.1.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.1.1.cjs
20 changes: 20 additions & 0 deletions near-workspaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
These tests use [near-workspaces-ava](https://github.com/near/workspaces-js/tree/main/packages/ava): delightful, deterministic local testing for NEAR smart contracts.

You will need to install [NodeJS](https://nodejs.dev/). Then you can use the `scripts` defined in [package.json](./package.json):

npm run test

If you want to run `near-workspaces-ava` or `ava` directly, you can use [npx](https://nodejs.dev/learn/the-npx-nodejs-package-runner):

npx near-workspaces-ava --help
npx ava --help

To run only one test file:

npm run test "**/main*" # matches test files starting with "main"
npm run test "**/whatever/**/*" # matches test files in the "whatever" directory

To run only one test:

npm run test -- -m "root sets*" # matches tests with titles starting with "root sets"
yarn test -m "root sets*" # same thing using yarn instead of npm, see https://yarnpkg.com/
66 changes: 66 additions & 0 deletions near-workspaces/__tests__/main.ava.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Start off by importing Workspace from chain-tests-ava.
*/
import { Workspace } from 'near-workspaces-ava'
import { NFTContractMetadata } from '../../as/cNFT/assembly/models/persistent_nft_contract_metadata'

/** @todo move these into separate file */

const ONE_NEAR = '1000000000000000000000000'
const CONTRACT_MINT_PRICE = ONE_NEAR
const CONTRACT_METADATA = {
spec: 'nft-1.0.0',
name: 'nftExample',
symbol: 'NFTEXAMPLE',
icon: '',
base_uri: 'https://picsum.photos',
reference: '',
reference_hash: '',
packages_script: '',
render_script: '',
style_css: '',
parameters: '',
}
const CONTRACT_EXTRA = {
mint_price: CONTRACT_MINT_PRICE,
max_copies: 100,
default_max_len_payout: 20,
mints_per_address: 50,
mint_payee_id: 'jenny.test.near',
mint_royalty_id: 'jenny.test.near',
mint_royalty_amount: 10,
}

/**
* Initialize a new workspace. In local sandbox mode
*/
const workspace = Workspace.init(async ({ root }) => {
const alice = await root.createAccount('alice')

const contract = await root.createAndDeploy(
'cnft',
'../build/release/cNFT.wasm',
{
method: 'init',
args: {
contract_metadata: CONTRACT_METADATA,
contract_extra: CONTRACT_EXTRA,
},
}
)

return { alice, contract }
})

workspace.test(
'contract initialized in Workspace.init',
async (test, { contract }) => {
// If you want to store a `view` in a local variable, you can inform
// TypeScript what sort of return value you expect.
const aliceStatus: NFTContractMetadata = await contract.view(
'nft_metadata'
)

test.deepEqual(aliceStatus, CONTRACT_METADATA)
}
)
1 change: 1 addition & 0 deletions near-workspaces/ava.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('near-workspaces-ava/ava.config.cjs');
10 changes: 10 additions & 0 deletions near-workspaces/ava.testnet.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
...require('near-workspaces-ava/ava.testnet.config.cjs'),
...require('./ava.config.cjs'),
};

// Add files you only want to run in Sandbox mode here
module.exports.files.push(
// '!__tests__/example-file-name*',
// '!__tests__/another-example-file-name*',
);
Loading