chore: add tests for all contract method return types

Add tests for non-constant contract method return types:
1. `void`
2. `?TransactionResponse` or `Option[TransactionRepsonse]`
3. `Confirmable`
This commit is contained in:
Eric Mastro 2022-05-24 15:13:25 +10:00 committed by markspanbroek
parent fff0d189a5
commit e6c9b59cfb
1 changed files with 27 additions and 0 deletions

View File

@ -60,6 +60,33 @@ suite "Contracts":
await mint(token, accounts[1], 100.u256)
check (await balanceOf(token, accounts[1])) == 0.u256
test "can call non-constant functions without a return type":
token = TestToken.new(token.address, provider.getSigner())
proc mint(token: TestToken, holder: Address, amount: UInt256) {.contract.}
await token.mint(accounts[1], 100.u256)
check (await balanceOf(token, accounts[1])) == 100.u256
test "can call non-constant functions with a ?TransactionResponse return type":
token = TestToken.new(token.address, provider.getSigner())
proc mint(token: TestToken,
holder: Address,
amount: UInt256): ?TransactionResponse {.contract.}
let txResp = await token.mint(accounts[1], 100.u256)
# `of` instead of `is` due to v1.4.8 compiler error:
# "invalid type: 'type Confirmable' for var"
check txResp of (?TransactionResponse)
check txResp.isSome
test "can call non-constant functions with a Confirmable return type":
token = TestToken.new(token.address, provider.getSigner())
proc mint(token: TestToken,
holder: Address,
amount: UInt256): Confirmable {.contract.}
let txResp = await token.mint(accounts[1], 100.u256)
check txResp is Confirmable
check txResp.isSome
test "fails to compile when function has an implementation":
let works = compiles:
proc foo(token: TestToken, bar: Address) {.contract.} = discard