Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail when outgoing message amounts sum to more than current balance #989

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/eval/Eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -900,16 +900,11 @@ let post_process_msgs cstate outs =
List.fold_left amounts ~init:zero ~f:(fun z a -> add z a)
in
let open ContractState in
if compare cstate.balance to_be_transferred < 0 then
fail0
@@ sprintf
"The balance is too low (%s) to transfer all the funds in the \
messages (%s)"
(to_string cstate.balance)
(to_string to_be_transferred)
else
let balance = sub cstate.balance to_be_transferred in
pure { cstate with balance }
let balance =
if compare cstate.balance to_be_transferred < 0 then Uint128.zero
else sub cstate.balance to_be_transferred
in
pure { cstate with balance }

(*
Handle message:
Expand Down
5 changes: 4 additions & 1 deletion tests/checker/good/gold/multiple-msgs.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"vname": "HelloWorld",
"params": [],
"fields": [],
"transitions": [ { "vname": "multipleMsgs", "params": [] } ],
"transitions": [
{ "vname": "multipleMsgs", "params": [] },
{ "vname": "multipleAmountMsgs", "params": [] }
],
"procedures": [],
"events": [],
"ADTs": [
Expand Down
8 changes: 8 additions & 0 deletions tests/contracts/multiple-msgs.scilla
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ transition multipleMsgs()
msgs2 = Cons {Message} msg2 msgs1;
send msgs2
end

transition multipleAmountMsgs()
msg1 = {_tag : ""; _recipient : _sender; _amount : Uint128 100};
msg2 = {_tag : ""; _recipient : _sender; _amount : Uint128 100};
msgs1 = one_msg msg1;
msgs2 = Cons {Message} msg2 msgs1;
send msgs2
end
2 changes: 1 addition & 1 deletion tests/runner/Testcontracts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ let contract_tests env =
>::: build_contract_tests env "map_corners_test" succ_code 51 53
[];
"multiple_msgs_test"
>::: build_contract_tests env "multiple-msgs" succ_code 1 1 [];
>::: build_contract_tests env "multiple-msgs" succ_code 1 3 [];
"listiter"
>::: build_contract_tests env "listiter" succ_code 1 1 [];
"polynetwork"
Expand Down
1 change: 1 addition & 0 deletions tests/runner/multiple-msgs/blockchain_2.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/multiple-msgs/blockchain_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ { "vname": "BLOCKNUMBER", "type": "BNum", "value": "100" } ]
7 changes: 7 additions & 0 deletions tests/runner/multiple-msgs/message_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_tag": "multipleAmountMsgs",
"_amount": "0",
"_sender": "0x1234567890123456789012345678906784567890",
"params": [],
"_origin": "0x1234567890123456789012345678906784567890"
}
7 changes: 7 additions & 0 deletions tests/runner/multiple-msgs/message_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_tag": "multipleAmountMsgs",
"_amount": "0",
"_sender": "0x1234567890123456789012345678906784567890",
"params": [],
"_origin": "0x1234567890123456789012345678906784567890"
}
21 changes: 21 additions & 0 deletions tests/runner/multiple-msgs/output_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"scilla_major_version": "0",
"gas_remaining": "7938",
"_accepted": "false",
"messages": [
{
"_tag": "",
"_amount": "100",
"_recipient": "0x1234567890123456789012345678906784567890",
"params": []
},
{
"_tag": "",
"_amount": "100",
"_recipient": "0x1234567890123456789012345678906784567890",
"params": []
}
],
"states": [ { "vname": "_balance", "type": "Uint128", "value": "0" } ],
"events": []
}
21 changes: 21 additions & 0 deletions tests/runner/multiple-msgs/output_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"scilla_major_version": "0",
"gas_remaining": "7938",
"_accepted": "false",
"messages": [
{
"_tag": "",
"_amount": "100",
"_recipient": "0x1234567890123456789012345678906784567890",
"params": []
},
{
"_tag": "",
"_amount": "100",
"_recipient": "0x1234567890123456789012345678906784567890",
"params": []
}
],
"states": [ { "vname": "_balance", "type": "Uint128", "value": "50" } ],
"events": []
}
5 changes: 5 additions & 0 deletions tests/runner/multiple-msgs/state_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{ "vname": "_balance",
"type": "Uint128",
"value": "150" }
]
5 changes: 5 additions & 0 deletions tests/runner/multiple-msgs/state_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{ "vname": "_balance",
"type": "Uint128",
"value": "250" }
]