From c7290a1bcff119ea576f060280fbe56ef666ca5f Mon Sep 17 00:00:00 2001 From: Vaivaswatha Nagaraj Date: Mon, 12 Apr 2021 10:08:24 +0530 Subject: [PATCH 1/5] Add addfunds tests for unittesting from blockchain code --- tests/contracts/addfunds.scilla | 11 ++++++++ tests/contracts/addfunds_proxy.scilla | 28 +++++++++++++++++++ tests/runner/Testcontracts.ml | 6 +++- tests/runner/addfunds/blockchain_1.json | 1 + tests/runner/addfunds/init.json | 17 +++++++++++ tests/runner/addfunds/message_1.json | 13 +++++++++ tests/runner/addfunds/output_1.json | 19 +++++++++++++ tests/runner/addfunds/state_1.json | 19 +++++++++++++ tests/runner/addfunds_proxy/blockchain_1.json | 1 + tests/runner/addfunds_proxy/blockchain_2.json | 1 + tests/runner/addfunds_proxy/init.json | 22 +++++++++++++++ tests/runner/addfunds_proxy/message_1.json | 7 +++++ tests/runner/addfunds_proxy/message_2.json | 7 +++++ tests/runner/addfunds_proxy/output_1.json | 28 +++++++++++++++++++ tests/runner/addfunds_proxy/output_2.json | 27 ++++++++++++++++++ tests/runner/addfunds_proxy/state_1.json | 24 ++++++++++++++++ tests/runner/addfunds_proxy/state_2.json | 24 ++++++++++++++++ 17 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 tests/contracts/addfunds.scilla create mode 100644 tests/contracts/addfunds_proxy.scilla create mode 100644 tests/runner/addfunds/blockchain_1.json create mode 100644 tests/runner/addfunds/init.json create mode 100644 tests/runner/addfunds/message_1.json create mode 100644 tests/runner/addfunds/output_1.json create mode 100644 tests/runner/addfunds/state_1.json create mode 100644 tests/runner/addfunds_proxy/blockchain_1.json create mode 100644 tests/runner/addfunds_proxy/blockchain_2.json create mode 100644 tests/runner/addfunds_proxy/init.json create mode 100644 tests/runner/addfunds_proxy/message_1.json create mode 100644 tests/runner/addfunds_proxy/message_2.json create mode 100644 tests/runner/addfunds_proxy/output_1.json create mode 100644 tests/runner/addfunds_proxy/output_2.json create mode 100644 tests/runner/addfunds_proxy/state_1.json create mode 100644 tests/runner/addfunds_proxy/state_2.json diff --git a/tests/contracts/addfunds.scilla b/tests/contracts/addfunds.scilla new file mode 100644 index 000000000..059bd3f16 --- /dev/null +++ b/tests/contracts/addfunds.scilla @@ -0,0 +1,11 @@ +scilla_version 0 + +library SimpleImpl + +contract SimpleImpl() + +transition AddFunds(initiator: ByStr20) + accept; + e = { _eventname : "Funds deposit "; funder : initiator }; + event e +end \ No newline at end of file diff --git a/tests/contracts/addfunds_proxy.scilla b/tests/contracts/addfunds_proxy.scilla new file mode 100644 index 000000000..783420427 --- /dev/null +++ b/tests/contracts/addfunds_proxy.scilla @@ -0,0 +1,28 @@ +scilla_version 0 + +library SimpleProxy + +let one_msg = + fun (m: Message) => + let e = Nil {Message} in + Cons {Message} m e + +contract SimpleProxy( + init_implementation: ByStr20 +) + +field implementation: ByStr20 = init_implementation + +transition AddFunds() + current_impl <- implementation; + accept; + msg = {_tag: "AddFunds"; _recipient: current_impl; _amount: _amount; initiator: _sender}; + msgs = one_msg msg; + send msgs +end + +transition SelfAddFunds() + accept; + e = { _eventname : "Self Add Funds deposit "; funder : _sender; amount: _amount }; + event e +end \ No newline at end of file diff --git a/tests/runner/Testcontracts.ml b/tests/runner/Testcontracts.ml index 2ae2dfb08..d7c10f938 100644 --- a/tests/runner/Testcontracts.ml +++ b/tests/runner/Testcontracts.ml @@ -463,7 +463,11 @@ let contract_tests env = "polymorphic_address" >::: build_contract_tests ~pplit:false env "address_list_traversal" succ_code 1 2 []; - ]; + "addfunds_proxy" + >::: build_contract_tests env "addfunds_proxy" succ_code 1 2 []; + "addfunds" + >::: build_contract_tests env "addfunds" succ_code 1 1 []; + ]; "these_tests_must_FAIL" >::: [ "helloWorld_f" diff --git a/tests/runner/addfunds/blockchain_1.json b/tests/runner/addfunds/blockchain_1.json new file mode 100644 index 000000000..9c3af9b93 --- /dev/null +++ b/tests/runner/addfunds/blockchain_1.json @@ -0,0 +1 @@ +[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ] \ No newline at end of file diff --git a/tests/runner/addfunds/init.json b/tests/runner/addfunds/init.json new file mode 100644 index 000000000..eaae7b188 --- /dev/null +++ b/tests/runner/addfunds/init.json @@ -0,0 +1,17 @@ +[ + { + "vname" : "_scilla_version", + "type" : "Uint32", + "value" : "0" + }, + { + "vname" : "_this_address", + "type" : "ByStr20", + "value" : "0xabfeccdc9012345678901234567890f777567890" + }, + { + "vname" : "_creation_block", + "type" : "BNum", + "value" : "1" + } +] diff --git a/tests/runner/addfunds/message_1.json b/tests/runner/addfunds/message_1.json new file mode 100644 index 000000000..a7a4f4e3d --- /dev/null +++ b/tests/runner/addfunds/message_1.json @@ -0,0 +1,13 @@ +{ + "_tag": "AddFunds", + "_amount": "100", + "_sender": "0x12345678901234567890123456789012345678ab", + "params": [ + { + "vname" : "initiator", + "type" : "ByStr20", + "value" : "0x52345678901234567890123456789012345678ab" + } + ], + "_origin": "0x12345678901234567890123456789012345678ab" +} diff --git a/tests/runner/addfunds/output_1.json b/tests/runner/addfunds/output_1.json new file mode 100644 index 000000000..74f931c16 --- /dev/null +++ b/tests/runner/addfunds/output_1.json @@ -0,0 +1,19 @@ +{ + "scilla_major_version": "0", + "gas_remaining": "7944", + "_accepted": "true", + "messages": [], + "states": [ { "vname": "_balance", "type": "Uint128", "value": "100" } ], + "events": [ + { + "_eventname": "Funds deposit ", + "params": [ + { + "vname": "funder", + "type": "ByStr20", + "value": "0x52345678901234567890123456789012345678ab" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/runner/addfunds/state_1.json b/tests/runner/addfunds/state_1.json new file mode 100644 index 000000000..6efc2d4a1 --- /dev/null +++ b/tests/runner/addfunds/state_1.json @@ -0,0 +1,19 @@ +[ + { + "vname": "_balance", + "type": "Uint128", + "value": "0" + }, + { + "vname": "_external", + "type": "Unit", + "value": [ + { + "address": "0x12345678901234567890123456789012345678ab", + "state": [ + { "vname": "_balance", "type": "Uint128", "value": "142" } + ] + } + ] + } +] diff --git a/tests/runner/addfunds_proxy/blockchain_1.json b/tests/runner/addfunds_proxy/blockchain_1.json new file mode 100644 index 000000000..9c3af9b93 --- /dev/null +++ b/tests/runner/addfunds_proxy/blockchain_1.json @@ -0,0 +1 @@ +[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ] \ No newline at end of file diff --git a/tests/runner/addfunds_proxy/blockchain_2.json b/tests/runner/addfunds_proxy/blockchain_2.json new file mode 100644 index 000000000..9c3af9b93 --- /dev/null +++ b/tests/runner/addfunds_proxy/blockchain_2.json @@ -0,0 +1 @@ +[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ] \ No newline at end of file diff --git a/tests/runner/addfunds_proxy/init.json b/tests/runner/addfunds_proxy/init.json new file mode 100644 index 000000000..541513f09 --- /dev/null +++ b/tests/runner/addfunds_proxy/init.json @@ -0,0 +1,22 @@ +[ + { + "vname" : "_scilla_version", + "type" : "Uint32", + "value" : "0" + }, + { + "vname" : "_this_address", + "type" : "ByStr20", + "value" : "0xabfeccdc9012345678901234567890f777567890" + }, + { + "vname" : "_creation_block", + "type" : "BNum", + "value" : "1" + }, + { + "vname": "init_implementation", + "type": "ByStr20", + "value": "0xff345678901234567890123456789012345678ab" + } +] diff --git a/tests/runner/addfunds_proxy/message_1.json b/tests/runner/addfunds_proxy/message_1.json new file mode 100644 index 000000000..9cbb8d3c4 --- /dev/null +++ b/tests/runner/addfunds_proxy/message_1.json @@ -0,0 +1,7 @@ +{ + "_tag": "AddFunds", + "_amount": "100", + "_sender": "0x12345678901234567890123456789012345678ab", + "params": [], + "_origin": "0x12345678901234567890123456789012345678ab" +} diff --git a/tests/runner/addfunds_proxy/message_2.json b/tests/runner/addfunds_proxy/message_2.json new file mode 100644 index 000000000..c424e4c2b --- /dev/null +++ b/tests/runner/addfunds_proxy/message_2.json @@ -0,0 +1,7 @@ +{ + "_tag": "SelfAddFunds", + "_amount": "100", + "_sender": "0x12345678901234567890123456789012345678ab", + "params": [], + "_origin": "0x12345678901234567890123456789012345678ab" +} diff --git a/tests/runner/addfunds_proxy/output_1.json b/tests/runner/addfunds_proxy/output_1.json new file mode 100644 index 000000000..3eed58bca --- /dev/null +++ b/tests/runner/addfunds_proxy/output_1.json @@ -0,0 +1,28 @@ +{ + "scilla_major_version": "0", + "gas_remaining": "7951", + "_accepted": "true", + "messages": [ + { + "_tag": "AddFunds", + "_amount": "100", + "_recipient": "0xff345678901234567890123456789012345678ab", + "params": [ + { + "vname": "initiator", + "type": "ByStr20", + "value": "0x12345678901234567890123456789012345678ab" + } + ] + } + ], + "states": [ + { "vname": "_balance", "type": "Uint128", "value": "0" }, + { + "vname": "implementation", + "type": "ByStr20", + "value": "0xff345678901234567890123456789012345678ab" + } + ], + "events": [] +} \ No newline at end of file diff --git a/tests/runner/addfunds_proxy/output_2.json b/tests/runner/addfunds_proxy/output_2.json new file mode 100644 index 000000000..1f7e3e90e --- /dev/null +++ b/tests/runner/addfunds_proxy/output_2.json @@ -0,0 +1,27 @@ +{ + "scilla_major_version": "0", + "gas_remaining": "7958", + "_accepted": "true", + "messages": [], + "states": [ + { "vname": "_balance", "type": "Uint128", "value": "100" }, + { + "vname": "implementation", + "type": "ByStr20", + "value": "0xff345678901234567890123456789012345678ab" + } + ], + "events": [ + { + "_eventname": "Self Add Funds deposit ", + "params": [ + { + "vname": "funder", + "type": "ByStr20", + "value": "0x12345678901234567890123456789012345678ab" + }, + { "vname": "amount", "type": "Uint128", "value": "100" } + ] + } + ] +} \ No newline at end of file diff --git a/tests/runner/addfunds_proxy/state_1.json b/tests/runner/addfunds_proxy/state_1.json new file mode 100644 index 000000000..dd1bfd858 --- /dev/null +++ b/tests/runner/addfunds_proxy/state_1.json @@ -0,0 +1,24 @@ +[ + { + "vname": "_balance", + "type": "Uint128", + "value": "0" + }, + { + "vname": "implementation", + "type": "ByStr20", + "value": "0xff345678901234567890123456789012345678ab" + }, + { + "vname": "_external", + "type": "Unit", + "value": [ + { + "address": "0x12345678901234567890123456789012345678ab", + "state": [ + { "vname": "_balance", "type": "Uint128", "value": "142" } + ] + } + ] + } +] diff --git a/tests/runner/addfunds_proxy/state_2.json b/tests/runner/addfunds_proxy/state_2.json new file mode 100644 index 000000000..dd1bfd858 --- /dev/null +++ b/tests/runner/addfunds_proxy/state_2.json @@ -0,0 +1,24 @@ +[ + { + "vname": "_balance", + "type": "Uint128", + "value": "0" + }, + { + "vname": "implementation", + "type": "ByStr20", + "value": "0xff345678901234567890123456789012345678ab" + }, + { + "vname": "_external", + "type": "Unit", + "value": [ + { + "address": "0x12345678901234567890123456789012345678ab", + "state": [ + { "vname": "_balance", "type": "Uint128", "value": "142" } + ] + } + ] + } +] From b27201c89d6b1610a6fde01f41537a839f1555a0 Mon Sep 17 00:00:00 2001 From: Vaivaswatha Nagaraj Date: Mon, 12 Apr 2021 10:49:20 +0530 Subject: [PATCH 2/5] Add output files for chain-call-balance tests --- .../runner/chain-call-balance-1/output_1.json | 21 ++++++++++++++++++ .../runner/chain-call-balance-1/state_1.json | 22 ++++++++++++++++++- .../runner/chain-call-balance-2/output_1.json | 15 +++++++++++++ .../runner/chain-call-balance-2/state_1.json | 22 ++++++++++++++++++- .../runner/chain-call-balance-3/output_1.json | 15 +++++++++++++ .../runner/chain-call-balance-3/state_1.json | 22 ++++++++++++++++++- 6 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 tests/runner/chain-call-balance-1/output_1.json create mode 100644 tests/runner/chain-call-balance-2/output_1.json create mode 100644 tests/runner/chain-call-balance-3/output_1.json diff --git a/tests/runner/chain-call-balance-1/output_1.json b/tests/runner/chain-call-balance-1/output_1.json new file mode 100644 index 000000000..8da391f92 --- /dev/null +++ b/tests/runner/chain-call-balance-1/output_1.json @@ -0,0 +1,21 @@ +{ + "scilla_major_version": "0", + "gas_remaining": "7915", + "_accepted": "true", + "messages": [ + { + "_tag": "b_accept_callC", + "_amount": "50", + "_recipient": "0x22345678901234567890123456789012345678ab", + "params": [ + { + "vname": "addrC", + "type": "ByStr20", + "value": "0x32345678901234567890123456789012345678ab" + } + ] + } + ], + "states": [ { "vname": "_balance", "type": "Uint128", "value": "100" } ], + "events": [] +} \ No newline at end of file diff --git a/tests/runner/chain-call-balance-1/state_1.json b/tests/runner/chain-call-balance-1/state_1.json index 3cb59b6a2..bc1954bba 100644 --- a/tests/runner/chain-call-balance-1/state_1.json +++ b/tests/runner/chain-call-balance-1/state_1.json @@ -1,3 +1,23 @@ [ - { "vname": "_balance", "type": "Uint128", "value": "100" } + { + "vname": "_balance", + "type": "Uint128", + "value": "100" + }, + { + "vname": "_external", + "type": "Unit", + "value": [ + { + "address": "0x02345678901234567890123456789012345678ab", + "state": [ + { + "vname": "_balance", + "type": "Uint128", + "value": "100" + } + ] + } + ] + } ] diff --git a/tests/runner/chain-call-balance-2/output_1.json b/tests/runner/chain-call-balance-2/output_1.json new file mode 100644 index 000000000..cffa10471 --- /dev/null +++ b/tests/runner/chain-call-balance-2/output_1.json @@ -0,0 +1,15 @@ +{ + "scilla_major_version": "0", + "gas_remaining": "7939", + "_accepted": "true", + "messages": [ + { + "_tag": "c_noaccept", + "_amount": "50", + "_recipient": "0x32345678901234567890123456789012345678ab", + "params": [] + } + ], + "states": [ { "vname": "_balance", "type": "Uint128", "value": "100" } ], + "events": [] +} \ No newline at end of file diff --git a/tests/runner/chain-call-balance-2/state_1.json b/tests/runner/chain-call-balance-2/state_1.json index 3cb59b6a2..a01821b6a 100644 --- a/tests/runner/chain-call-balance-2/state_1.json +++ b/tests/runner/chain-call-balance-2/state_1.json @@ -1,3 +1,23 @@ [ - { "vname": "_balance", "type": "Uint128", "value": "100" } + { + "vname": "_balance", + "type": "Uint128", + "value": "100" + }, + { + "vname": "_external", + "type": "Unit", + "value": [ + { + "address": "0x12345678901234567890123456789012345678ab", + "state": [ + { + "vname": "_balance", + "type": "Uint128", + "value": "100" + } + ] + } + ] + } ] diff --git a/tests/runner/chain-call-balance-3/output_1.json b/tests/runner/chain-call-balance-3/output_1.json new file mode 100644 index 000000000..9a36ba0ce --- /dev/null +++ b/tests/runner/chain-call-balance-3/output_1.json @@ -0,0 +1,15 @@ +{ + "scilla_major_version": "0", + "gas_remaining": "7959", + "_accepted": "false", + "messages": [ + { + "_tag": "", + "_amount": "0", + "_recipient": "0xabfeccdc9012345678901234567890f777567890", + "params": [] + } + ], + "states": [ { "vname": "_balance", "type": "Uint128", "value": "100" } ], + "events": [] +} \ No newline at end of file diff --git a/tests/runner/chain-call-balance-3/state_1.json b/tests/runner/chain-call-balance-3/state_1.json index 3cb59b6a2..bc1954bba 100644 --- a/tests/runner/chain-call-balance-3/state_1.json +++ b/tests/runner/chain-call-balance-3/state_1.json @@ -1,3 +1,23 @@ [ - { "vname": "_balance", "type": "Uint128", "value": "100" } + { + "vname": "_balance", + "type": "Uint128", + "value": "100" + }, + { + "vname": "_external", + "type": "Unit", + "value": [ + { + "address": "0x02345678901234567890123456789012345678ab", + "state": [ + { + "vname": "_balance", + "type": "Uint128", + "value": "100" + } + ] + } + ] + } ] From 5c4fd84b095afa1593bfd909a8fe525676f2549c Mon Sep 17 00:00:00 2001 From: Vaivaswatha Nagaraj Date: Mon, 12 Apr 2021 10:51:43 +0530 Subject: [PATCH 3/5] Add chain-call-balance tests to testsuite --- tests/runner/Testcontracts.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/runner/Testcontracts.ml b/tests/runner/Testcontracts.ml index d7c10f938..b652bca7f 100644 --- a/tests/runner/Testcontracts.ml +++ b/tests/runner/Testcontracts.ml @@ -467,6 +467,12 @@ let contract_tests env = >::: build_contract_tests env "addfunds_proxy" succ_code 1 2 []; "addfunds" >::: build_contract_tests env "addfunds" succ_code 1 1 []; + "chain-call-balance-1" + >::: build_contract_tests env "chain-call-balance-1" succ_code 1 1 []; + "chain-call-balance-2" + >::: build_contract_tests env "chain-call-balance-2" succ_code 1 1 []; + "chain-call-balance-3" + >::: build_contract_tests env "chain-call-balance-3" succ_code 1 1 []; ]; "these_tests_must_FAIL" >::: [ From 0c13652a47d11adfb30b14c3ceaa784402cf5107 Mon Sep 17 00:00:00 2001 From: Vaivaswatha Nagaraj Date: Mon, 12 Apr 2021 22:57:57 +0530 Subject: [PATCH 4/5] Fix bug in testing sender balance before accepting --- src/eval/EvalUtil.ml | 9 +++++++-- tests/runner/remote_state_reads/output_127.json | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/eval/EvalUtil.ml b/src/eval/EvalUtil.ml index 96a136a0a..724658533 100644 --- a/src/eval/EvalUtil.ml +++ b/src/eval/EvalUtil.ml @@ -341,8 +341,13 @@ module Configuration = struct let incoming' = st.incoming_funds in match sender_balance_l with | UintLit (Uint128L sender_balance) -> - if Uint128.compare incoming' sender_balance >= 0 then - fail0 "Insufficient sender balance for acceptance." + if Uint128.compare incoming' sender_balance > 0 then + fail0 + ("Insufficient sender balance for acceptance. Incoming vs \ + sender_balance: " + ^ Uint128.to_string incoming' + ^ " vs " + ^ Uint128.to_string sender_balance) else if (* Although unsigned integer is used, and this check isn't * necessary, we have it just in case, somehow a malformed diff --git a/tests/runner/remote_state_reads/output_127.json b/tests/runner/remote_state_reads/output_127.json index 069377e6e..ca600122e 100644 --- a/tests/runner/remote_state_reads/output_127.json +++ b/tests/runner/remote_state_reads/output_127.json @@ -2,7 +2,8 @@ "gas_remaining": "7966", "errors": [ { - "error_message": "Insufficient sender balance for acceptance.", + "error_message": + "Insufficient sender balance for acceptance. Incoming vs sender_balance: 100 vs 50", "start_location": { "file": "", "line": 0, "column": 0 }, "end_location": { "file": "", "line": 0, "column": 0 } } From 6d56415b87a2487efc3266837d146edb49a6b13e Mon Sep 17 00:00:00 2001 From: Jacob Johannsen Date: Mon, 12 Apr 2021 20:17:37 +0200 Subject: [PATCH 5/5] fmt --- tests/runner/Testcontracts.ml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/runner/Testcontracts.ml b/tests/runner/Testcontracts.ml index b652bca7f..f2561a81e 100644 --- a/tests/runner/Testcontracts.ml +++ b/tests/runner/Testcontracts.ml @@ -468,12 +468,15 @@ let contract_tests env = "addfunds" >::: build_contract_tests env "addfunds" succ_code 1 1 []; "chain-call-balance-1" - >::: build_contract_tests env "chain-call-balance-1" succ_code 1 1 []; + >::: build_contract_tests env "chain-call-balance-1" succ_code 1 + 1 []; "chain-call-balance-2" - >::: build_contract_tests env "chain-call-balance-2" succ_code 1 1 []; + >::: build_contract_tests env "chain-call-balance-2" succ_code 1 + 1 []; "chain-call-balance-3" - >::: build_contract_tests env "chain-call-balance-3" succ_code 1 1 []; - ]; + >::: build_contract_tests env "chain-call-balance-3" succ_code 1 + 1 []; + ]; "these_tests_must_FAIL" >::: [ "helloWorld_f"