Fix: handle dynamically sized return values

Dynamically sized return values such as strings and
sequences were not decoded as part of a tuple, leading
to a difference in byte representation.
This commit is contained in:
Mark Spanbroek 2022-06-08 11:17:16 +02:00 committed by markspanbroek
parent 801bf19157
commit e61c70f5ba
2 changed files with 4 additions and 2 deletions

View File

@ -53,9 +53,9 @@ proc createTransaction(contract: Contract,
Transaction(to: contract.address, data: data)
proc decodeResponse(T: type, bytes: seq[byte]): T =
without decoded =? AbiDecoder.decode(bytes, T):
without decoded =? AbiDecoder.decode(bytes, (T,)):
raiseContractError "unable to decode return value as " & $T
return decoded
return decoded[0]
proc call(contract: Contract,
function: string,

View File

@ -16,6 +16,7 @@ type
receiver {.indexed.}: Address
value: UInt256
method name*(erc20: Erc20): string {.base, contract, view.}
method totalSupply*(erc20: Erc20): UInt256 {.base, contract, view.}
method balanceOf*(erc20: Erc20, account: Address): UInt256 {.base, contract, view.}
method allowance*(erc20: Erc20, owner, spender: Address): UInt256 {.base, contract, view.}
@ -40,6 +41,7 @@ suite "Contracts":
discard await provider.send("evm_revert", @[snapshot])
test "can call constant functions":
check (await token.name()) == "TestToken"
check (await token.totalSupply()) == 0.u256
check (await token.balanceOf(accounts[0])) == 0.u256
check (await token.allowance(accounts[0], accounts[1])) == 0.u256