Skip to content

Commit

Permalink
Merge pull request #978 from Zilliqa/addfunds_test
Browse files Browse the repository at this point in the history
Add AddFunds test, to be used from the blockchain unit tests
  • Loading branch information
ansnunez authored Apr 13, 2021
2 parents 994b231 + 6d56415 commit d4f6509
Show file tree
Hide file tree
Showing 25 changed files with 385 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/eval/EvalUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/contracts/addfunds.scilla
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions tests/contracts/addfunds_proxy.scilla
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/runner/Testcontracts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,19 @@ 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 [];
"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"
>::: [
Expand Down
1 change: 1 addition & 0 deletions tests/runner/addfunds/blockchain_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ]
17 changes: 17 additions & 0 deletions tests/runner/addfunds/init.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
13 changes: 13 additions & 0 deletions tests/runner/addfunds/message_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_tag": "AddFunds",
"_amount": "100",
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [
{
"vname" : "initiator",
"type" : "ByStr20",
"value" : "0x52345678901234567890123456789012345678ab"
}
],
"_origin": "0x12345678901234567890123456789012345678ab"
}
19 changes: 19 additions & 0 deletions tests/runner/addfunds/output_1.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
19 changes: 19 additions & 0 deletions tests/runner/addfunds/state_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"vname": "_balance",
"type": "Uint128",
"value": "0"
},
{
"vname": "_external",
"type": "Unit",
"value": [
{
"address": "0x12345678901234567890123456789012345678ab",
"state": [
{ "vname": "_balance", "type": "Uint128", "value": "142" }
]
}
]
}
]
1 change: 1 addition & 0 deletions tests/runner/addfunds_proxy/blockchain_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ]
1 change: 1 addition & 0 deletions tests/runner/addfunds_proxy/blockchain_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ]
22 changes: 22 additions & 0 deletions tests/runner/addfunds_proxy/init.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
7 changes: 7 additions & 0 deletions tests/runner/addfunds_proxy/message_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_tag": "AddFunds",
"_amount": "100",
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
7 changes: 7 additions & 0 deletions tests/runner/addfunds_proxy/message_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_tag": "SelfAddFunds",
"_amount": "100",
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
28 changes: 28 additions & 0 deletions tests/runner/addfunds_proxy/output_1.json
Original file line number Diff line number Diff line change
@@ -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": []
}
27 changes: 27 additions & 0 deletions tests/runner/addfunds_proxy/output_2.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}
]
}
24 changes: 24 additions & 0 deletions tests/runner/addfunds_proxy/state_1.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}
]
}
]
24 changes: 24 additions & 0 deletions tests/runner/addfunds_proxy/state_2.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}
]
}
]
21 changes: 21 additions & 0 deletions tests/runner/chain-call-balance-1/output_1.json
Original file line number Diff line number Diff line change
@@ -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": []
}
22 changes: 21 additions & 1 deletion tests/runner/chain-call-balance-1/state_1.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
]
15 changes: 15 additions & 0 deletions tests/runner/chain-call-balance-2/output_1.json
Original file line number Diff line number Diff line change
@@ -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": []
}
22 changes: 21 additions & 1 deletion tests/runner/chain-call-balance-2/state_1.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
]
Loading

0 comments on commit d4f6509

Please sign in to comment.