-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b136bff
commit 8702b7f
Showing
4 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
for file in test/vm/test_*.js; do | ||
echo "Unit tests [$file]" | ||
./build/tools/mmx_compile -e -f $file | ||
echo "Pass" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
interface __test; | ||
interface template; | ||
interface nft; | ||
|
||
const nft_binary = __test.compile("src/contract/nft.js"); | ||
|
||
const creator = "mmx1kx69pm743rshqac5lgcstlr8nq4t93hzm8gumkkxmp5y9fglnkes6ve09z"; | ||
|
||
const nft_addr = nft.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: nft_binary, | ||
init_args: [creator] | ||
}); | ||
|
||
const wallet = "mmx1e7yktu9vpeyq7hx39cmagzfp2um3kddwjf4tlt8j3kmktwc7fk6qmyc6ns"; | ||
|
||
nft.mint_to(wallet, null, {__test: 1, assert_fail: true}); | ||
nft.mint_to(wallet, null, {__test: 1, user: creator}); | ||
nft.mint_to(wallet, null, {__test: 1, user: creator, assert_fail: true}); | ||
|
||
__test.assert(__test.get_balance(wallet, nft_addr) == 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
interface __test; | ||
interface template; | ||
interface nft_1; | ||
interface nft_2; | ||
interface nft_test; | ||
|
||
const nft_binary = __test.compile("src/contract/nft.js"); | ||
const template_binary = __test.compile("src/contract/template.js"); | ||
|
||
const creator_skey = sha256("skey"); | ||
const creator_key = __test.get_public_key(creator_skey); | ||
const creator = to_string_bech32(sha256(creator_key)); | ||
|
||
const template_addr = template.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: template_binary, | ||
init_args: [creator] | ||
}); | ||
|
||
const txid = sha256("contract/nft_1"); | ||
|
||
const signature = __test.ecdsa_sign(creator_skey, txid); | ||
|
||
// fail due to invalid user | ||
nft_test.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: nft_binary, | ||
depends: {template: template_addr}, | ||
init_method: "init_n", | ||
init_args: [creator_key, 1, signature, {__test: 1, assert_fail: true}] | ||
}); | ||
|
||
// fail due to serial 0 | ||
nft_test.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: nft_binary, | ||
depends: {template: template_addr}, | ||
init_method: "init_n", | ||
init_args: [creator_key, 0, signature, {__test: 1, user: to_string_bech32(txid), assert_fail: true}] | ||
}); | ||
|
||
const nft_1_addr = nft_1.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: nft_binary, | ||
depends: {template: template_addr}, | ||
init_method: "init_n", | ||
init_args: [creator_key, 1, signature, {__test: 1, user: to_string_bech32(txid)}] | ||
}); | ||
|
||
// fail due to duplicate serial | ||
nft_test.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: nft_binary, | ||
depends: {template: template_addr}, | ||
init_method: "init_n", | ||
init_args: [creator_key, 1, signature, {__test: 1, user: to_string_bech32(txid), assert_fail: true}] | ||
}); | ||
|
||
const nft_2_addr = nft_2.__deploy({ | ||
__type: "mmx.contract.Executable", | ||
binary: nft_binary, | ||
depends: {template: template_addr}, | ||
init_method: "init_n", | ||
init_args: [creator_key, 2, signature, {__test: 1, user: to_string_bech32(txid)}] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters