Test for record field parse error
This commit is contained in:
parent
ee03442ddf
commit
96547ea2ec
@ -329,4 +329,7 @@ failing_contracts() ->
|
||||
<<"The init function should return the initial state as its result and cannot read the state,\n"
|
||||
"but it calls\n"
|
||||
" - state (at line 13, column 13)">>]}
|
||||
, {"field_parse_error",
|
||||
[<<"line 6, column 1: In field_parse_error at 5:26:\n"
|
||||
"Cannot use nested fields or keys in record construction: p.x\n">>]}
|
||||
].
|
||||
|
@ -62,7 +62,7 @@ simple_contracts_test_() ->
|
||||
%% Parse tests of example contracts
|
||||
[ {lists:concat(["Parse the ", Contract, " contract."]),
|
||||
fun() -> roundtrip_contract(Contract) end}
|
||||
|| Contract <- [counter, voting, all_syntax, '05_greeter', aeproof, multi_sig, simple_storage, withdrawal, fundme, dutch_auction] ]
|
||||
|| Contract <- [counter, voting, all_syntax, '05_greeter', aeproof, multi_sig, simple_storage, fundme, dutch_auction] ]
|
||||
}.
|
||||
|
||||
parse_contract(Name) ->
|
||||
|
5
test/contracts/field_parse_error.aes
Normal file
5
test/contracts/field_parse_error.aes
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
contract Fail =
|
||||
record pt = {x : int, y : int}
|
||||
record r = {p : pt}
|
||||
function fail() = {p.x = 0, p.y = 0}
|
@ -1,56 +0,0 @@
|
||||
/* Example from Solidity by Example
|
||||
http://solidity.readthedocs.io/en/develop/common-patterns.html
|
||||
|
||||
contract WithdrawalContract {
|
||||
address public richest
|
||||
uint public mostSent
|
||||
|
||||
mapping (address => uint) pendingWithdrawals
|
||||
|
||||
function WithdrawalContract() payable {
|
||||
richest = msg.sender
|
||||
mostSent = msg.value
|
||||
}
|
||||
|
||||
function becomeRichest() payable returns (bool) {
|
||||
if (msg.value > mostSent) {
|
||||
pendingWithdrawals[richest] += msg.value
|
||||
richest = msg.sender
|
||||
mostSent = msg.value
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function withdraw() {
|
||||
uint amount = pendingWithdrawals[msg.sender]
|
||||
// Remember to zero the pending refund before
|
||||
// sending to prevent re-entrancy attacks
|
||||
pendingWithdrawals[msg.sender] = 0
|
||||
msg.sender.transfer(amount)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
contract WithdrawalContract =
|
||||
|
||||
record state = { richest : address,
|
||||
mostSent : uint,
|
||||
pendingWithdrawals : map(address, uint) }
|
||||
|
||||
function becomeRichest() : result(bool) =
|
||||
if (call().value > state.mostSent)
|
||||
let totalAmount : uint = Map.get_(state.richest, pendingWithdrawals) + call().value
|
||||
{state = state{ pendingWithdrawals = Map.insert(state.richest, call().value, state.pendingWithdrawals),
|
||||
richest = call().sender,
|
||||
mostSent = call().value },
|
||||
result = true}
|
||||
else
|
||||
{result = false}
|
||||
|
||||
function withdraw() =
|
||||
let amount : uint = Map.get_(call().sender, state.pendingWithdrawals)
|
||||
{ state.pendingWithdrawals = Map.insert(call().sender, 0, state.pendingWithdrawals),
|
||||
transactions = spend_tx(amount, call().sender) }
|
Loading…
x
Reference in New Issue
Block a user