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:
parent
fff0d189a5
commit
e6c9b59cfb
|
@ -60,6 +60,33 @@ suite "Contracts":
|
||||||
await mint(token, accounts[1], 100.u256)
|
await mint(token, accounts[1], 100.u256)
|
||||||
check (await balanceOf(token, accounts[1])) == 0.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":
|
test "fails to compile when function has an implementation":
|
||||||
let works = compiles:
|
let works = compiles:
|
||||||
proc foo(token: TestToken, bar: Address) {.contract.} = discard
|
proc foo(token: TestToken, bar: Address) {.contract.} = discard
|
||||||
|
|
Loading…
Reference in New Issue