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

Move computations into library functions #585

Merged
merged 3 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/checker/good/gold/crowdfunding_proc.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"State variables": [
{ "field": "owner", "tag": "NotMoney" },
{ "field": "max_block", "tag": "NotMoney" },
{ "field": "goal", "tag": "Money" },
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
{ "field": "goal", "tag": "NoInfo" },
{ "field": "backers", "tag": "(Map Money)" },
{ "field": "funded", "tag": "NotMoney" }
],
Expand Down
66 changes: 39 additions & 27 deletions tests/contracts/crowdfunding_proc.scilla
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,35 @@ library Crowdfunding

let one_msg =
fun (msg : Message) =>
let nil_msg = Nil {Message} in
Cons {Message} msg nil_msg
let nil_msg = Nil {Message} in
Cons {Message} msg nil_msg

let blk_leq =
fun (blk1 : BNum) =>
fun (blk2 : BNum) =>
let bc1 = builtin blt blk1 blk2 in
let bc2 = builtin eq blk1 blk2 in
orb bc1 bc2

let bc1 = builtin blt blk1 blk2 in
let bc2 = builtin eq blk1 blk2 in
orb bc1 bc2

let get_funds_allowed =
fun (cur_block : BNum) =>
fun (max_block : BNum) =>
fun (balance : Uint128) =>
fun (goal : Uint128) =>
let in_time = blk_leq cur_block max_block in
let deadline_passed = negb in_time in
let target_not_reached = builtin lt balance goal in
let target_reached = negb target_not_reached in
andb deadline_passed target_reached

let claimback_allowed =
fun (balance : Uint128) =>
fun (goal : Uint128) =>
fun (already_funded : Bool) =>
let target_not_reached = builtin lt balance goal in
let not_already_funded = negb already_funded in
andb target_not_reached not_already_funded

let accepted_code = Int32 1
let missed_deadline_code = Int32 2
let already_backed_code = Int32 3
Expand Down Expand Up @@ -105,19 +124,15 @@ transition GetFunds ()
| False =>
GetFundsFailure not_owner_code
| True =>
blk <- & BLOCKNUMBER;
in_time = blk_leq blk max_block;
c1 = negb in_time;
bal <- _balance;
c2 = builtin lt bal goal;
c3 = negb c2;
c4 = andb c1 c3;
match c4 with
| False =>
blk <- & BLOCKNUMBER;
bal <- _balance;
allowed = get_funds_allowed blk max_block bal goal;
match allowed with
| False =>
GetFundsFailure cannot_get_funds
| True =>
| True =>
PerformGetFunds
end
end
end
end

Expand All @@ -144,16 +159,13 @@ transition ClaimBack ()
| False =>
ClaimBackFailure too_early_code
| True =>
bal <- _balance;
f <- funded;
c1 = builtin lt bal goal;
c2 = negb f;
(* Target has not been reached *)
c3 = andb c1 c2;
match c3 with
| False =>
bal <- _balance;
f <- funded;
allowed = claimback_allowed bal goal f;
match allowed with
| False =>
ClaimBackFailure cannot_reclaim_code
| True =>
| True =>
res <- backers[_sender];
match res with
| None =>
Expand All @@ -162,6 +174,6 @@ transition ClaimBack ()
| Some v =>
PerformClaimBack v
end
end
end
end
end
2 changes: 1 addition & 1 deletion tests/runner/crowdfunding_proc/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7590",
"gas_remaining": "7586",
"_accepted": "true",
"message": null,
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/crowdfunding_proc/output_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7591",
"gas_remaining": "7587",
"_accepted": "true",
"message": null,
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/crowdfunding_proc/output_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7609",
"gas_remaining": "7605",
"_accepted": "false",
"message": null,
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/crowdfunding_proc/output_4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7670",
"gas_remaining": "7666",
"_accepted": "false",
"message": null,
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/crowdfunding_proc/output_5.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7448",
"gas_remaining": "7441",
"_accepted": "false",
"message": {
"_tag": "",
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/crowdfunding_proc/output_6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7593",
"gas_remaining": "7589",
"_accepted": "true",
"message": null,
"states": [
Expand Down