From 7e45b464ddd532f84594c9d591cee3ef3b6d92e7 Mon Sep 17 00:00:00 2001 From: Max Wittal Date: Sat, 21 Jan 2023 19:08:01 +0100 Subject: [PATCH] tests --- test/code/contract_01.js | 30 ++++++++++++++++++++++++++++++ test/code/contract_02.js | 18 ++++++++++++++++++ test/code/test.js | 9 +++++++++ test/contracts/contract_02.json | 9 +++++++++ 4 files changed, 66 insertions(+) create mode 100644 test/code/contract_01.js create mode 100644 test/code/contract_02.js create mode 100644 test/contracts/contract_02.json diff --git a/test/code/contract_01.js b/test/code/contract_01.js new file mode 100644 index 000000000..73fbeafc1 --- /dev/null +++ b/test/code/contract_01.js @@ -0,0 +1,30 @@ + +var owner; +var value = 0; + +function init(owner_) { + owner = owner_; +} + +function add(count) public { + if(count > 10) { + fail("count > 10"); + } + value += count; +} + +function increment() public { + value++; +} + +function get_value() public const { + return value; +} + +function reset() public { + if(this.user != owner) { + fail("user != owner"); + } + value = 0; +} + diff --git a/test/code/contract_02.js b/test/code/contract_02.js new file mode 100644 index 000000000..7cd59224b --- /dev/null +++ b/test/code/contract_02.js @@ -0,0 +1,18 @@ + + +function init() {} + +function cross_add(value) public { + rcall("counter", "add", value); +} + +function cross_increment() public { + rcall("counter", "increment"); +} + +function cross_read_update() public { + const value = rcall("counter", "get_value"); + if(value % 2 != 0) { + rcall("counter", "increment"); + } +} diff --git a/test/code/test.js b/test/code/test.js index bb59313b9..b0242f0bd 100644 --- a/test/code/test.js +++ b/test/code/test.js @@ -12,3 +12,12 @@ for(var i = 0, test = 0; i < 6; ++i, i = i + 1) { for(const value of test) { map = value; } + +var owner; + +function check_owner() { + if (this.user != owner) { + fail("user != owner", 1); + } + var tmp = to_string_bech32(this.user); +} diff --git a/test/contracts/contract_02.json b/test/contracts/contract_02.json new file mode 100644 index 000000000..b566a8af3 --- /dev/null +++ b/test/contracts/contract_02.json @@ -0,0 +1,9 @@ +{ + "__type": "mmx.contract.Executable", + "name": "contract_02", + "binary": "mmx1davfr6uds7hr3g7vzd4qqvzzduatkpautsdvm5s452xqjsgcwdfsrq2daz", + "init_args": [], + "depends": { + "counter": "mmx1euuy4wtcvd50nat7q2gdcr78g37j6g3r6g7yjk3z9twr2fz45lqq7p0f4z" + } +} \ No newline at end of file