Skip to content

Commit

Permalink
more contract tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madMAx43v3r committed Oct 23, 2024
1 parent b136bff commit 8702b7f
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
9 changes: 9 additions & 0 deletions test/vm/contract_tests.sh
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
22 changes: 22 additions & 0 deletions test/vm/test_nft.js
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);
66 changes: 66 additions & 0 deletions test/vm/test_nft_n.js
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)}]
});
4 changes: 1 addition & 3 deletions test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ echo "Unit tests [vm_storage_tests]"

./test/vm/engine_tests.sh

echo "Unit tests [vm/test_plot_nft]"
./build/tools/mmx_compile -e -f test/vm/test_plot_nft.js
echo Pass
./test/vm/contract_tests.sh

0 comments on commit 8702b7f

Please sign in to comment.