-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1531 from informalsystems/gabriela/fix-nondet-picks
Fix nondet picks not being tracked correctly in the getting started spec
- Loading branch information
Showing
4 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module bank { | ||
/// A state variable to store the balance of each account | ||
var balances: str -> int | ||
|
||
pure val ADDRESSES = Set("alice", "bob", "charlie") | ||
|
||
action deposit(account, amount) = { | ||
// Increment balance of account by amount | ||
balances' = balances.setBy(account, curr => curr + amount) | ||
} | ||
|
||
action withdraw(account, amount) = { | ||
// Decrement balance of account by amount | ||
balances' = balances.setBy(account, curr => curr - amount) | ||
} | ||
|
||
action init = { | ||
// At the initial state, all balances are zero | ||
balances' = ADDRESSES.mapBy(_ => 0) | ||
} | ||
|
||
action step = { | ||
// Non-deterministically pick an address and an amount | ||
nondet account = ADDRESSES.oneOf() | ||
nondet amount = 1.to(100).oneOf() | ||
// Non-deterministically choose to either deposit or withdraw | ||
any { | ||
deposit(account, amount), | ||
withdraw(account, amount), | ||
} | ||
} | ||
|
||
/// An invariant stating that all accounts should have a non-negative balance | ||
val no_negatives = ADDRESSES.forall(addr => balances.get(addr) >= 0) | ||
} |