Skip to content

Commit

Permalink
add '%my account address%' variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kroggen committed Jul 14, 2024
1 parent c6c184a commit f14bbd9
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 3 deletions.
13 changes: 12 additions & 1 deletion contract/vm_dummy/test_files/feature_multicall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ function recv_aergo()
-- does nothing
end

abi.payable(recv_aergo)
function resend_to(address)
local amount = system.getAmount()
contract.send(address, amount)
return amount
end

function send_to(address, amount)
contract.send(address, amount)
end

abi.payable(recv_aergo, resend_to)
abi.register(send_to)
45 changes: 45 additions & 0 deletions contract/vm_dummy/vm_dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5689,6 +5689,51 @@ func TestComposableTransactions(t *testing.T) {
["assert","%last_result%","=","test2"]
]`)

multicall(t, bc, "ac3", `[
["call","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","sender"],
["assert","%last_result%","=","%my account address%"],
["call","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","is_contract","%my account address%"],
["assert","%last_result%","=",false],
["call","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","set","account","%my account address%"],
["call","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","get","account"],
["assert","%last_result%","=","%my account address%"]
]`)

// CALL + SEND

multicall(t, bc, "ac3", `[
["get balance","%my account address%"],
["store result as","my balance before"],
["get balance","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA"],
["store result as","contract balance before"],
["call + send","0.25 aergo","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","resend_to","%my account address%"],
["assert","%last_result%","=","250000000000000000"],
["get balance","%my account address%"],
["assert","%last_result%","=","%my balance before%"],
["get balance","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA"],
["assert","%last_result%","=","%contract balance before%"]
]`)

multicall(t, bc, "ac3", `[
["get balance","%my account address%"],
["store result as","my balance before"],
["get balance","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA"],
["store result as","contract balance before"],
["let","amount","1.5","aergo"],
["call + send","%amount%","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","recv_aergo"],
["assert","%my aergo balance%","<","%my balance before%"],
["get balance","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA"],
["assert","%last_result%",">","%contract balance before%"],
["call","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA","send_to","%my account address%","%amount%"],
["assert","%my aergo balance%","=","%my balance before%"],
["get balance","AmhbUWkqenFtgKLnbDd1NXHce7hn35pcHWYRWBnq5vauLfEQXXRA"],
["assert","%last_result%","=","%contract balance before%"]
]`)


// CALL LOOP

Expand Down
4 changes: 3 additions & 1 deletion contract/vm_multicall.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ end
function get_arg_value(varname, default)
local value = default
if varname == "my aergo balance" then
if varname == "my account address" then
value = system.getContractID()
elseif varname == "my aergo balance" then
value = action["get balance"]()
elseif vars[varname] ~= nil then
value = vars[varname]
Expand Down
4 changes: 3 additions & 1 deletion contract/vm_multicall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ end

function get_arg_value(varname, default)
local value = default
if varname == "my aergo balance" then
if varname == "my account address" then
value = system.getContractID()
elseif varname == "my aergo balance" then
value = action["get balance"]()
elseif vars[varname] ~= nil then
value = vars[varname]
Expand Down
45 changes: 45 additions & 0 deletions tests/test-multicall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,51 @@ multicall "ac3" '[
["assert","%last_result%","=","test2"]
]'

multicall "ac3" '[
["call","'$address'","sender"],
["assert","%last_result%","=","%my account address%"],
["call","'$address'","is_contract","%my account address%"],
["assert","%last_result%","=",false],
["call","'$address'","set","account","%my account address%"],
["call","'$address'","get","account"],
["assert","%last_result%","=","%my account address%"]
]'

# CALL + SEND

multicall "ac3" '[
["get balance","%my account address%"],
["store result as","my balance before"],
["get balance","'$address'"],
["store result as","contract balance before"],
["call + send","0.25 aergo","'$address'","resend_to","%my account address%"],
["assert","%last_result%","=","250000000000000000"],
["get balance","%my account address%"],
["assert","%last_result%","=","%my balance before%"],
["get balance","'$address'"],
["assert","%last_result%","=","%contract balance before%"]
]'

multicall "ac3" '[
["get balance","%my account address%"],
["store result as","my balance before"],
["get balance","'$address'"],
["store result as","contract balance before"],
["let","amount","1.5","aergo"],
["call + send","%amount%","'$address'","recv_aergo"],
["assert","%my aergo balance%","<","%my balance before%"],
["get balance","'$address'"],
["assert","%last_result%",">","%contract balance before%"],
["call","'$address'","send_to","%my account address%","%amount%"],
["assert","%my aergo balance%","=","%my balance before%"],
["get balance","'$address'"],
["assert","%last_result%","=","%contract balance before%"]
]'


# CALL LOOP

Expand Down

0 comments on commit f14bbd9

Please sign in to comment.