mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-01-11 16:14:36 +00:00
Return transaction response for ERC20 functions
Allows callers to wait for confirmation of the transaction
This commit is contained in:
parent
d7b7f67afb
commit
5ed3f15706
@ -46,17 +46,17 @@ method allowance*(token: Erc20Token,
|
||||
|
||||
method transfer*(token: Erc20Token,
|
||||
recipient: Address,
|
||||
amount: UInt256) {.base, contract.}
|
||||
amount: UInt256): ?TransactionResponse {.base, contract.}
|
||||
## Moves `amount` tokens from the caller's account to `recipient`.
|
||||
|
||||
method approve*(token: Erc20Token,
|
||||
spender: Address,
|
||||
amount: UInt256) {.base, contract.}
|
||||
amount: UInt256): ?TransactionResponse {.base, contract.}
|
||||
## Sets `amount` as the allowance of `spender` over the caller's tokens.
|
||||
|
||||
method transferFrom*(token: Erc20Token,
|
||||
spender: Address,
|
||||
recipient: Address,
|
||||
amount: UInt256) {.base, contract.}
|
||||
amount: UInt256): ?TransactionResponse {.base, contract.}
|
||||
## Moves `amount` tokens from `from` to `to` using the allowance
|
||||
## mechanism. `amount` is then deducted from the caller's allowance.
|
||||
|
@ -9,7 +9,6 @@ import ./miner
|
||||
import ./mocks
|
||||
|
||||
type
|
||||
|
||||
TestToken = ref object of Erc20Token
|
||||
|
||||
method mint(token: TestToken, holder: Address, amount: UInt256): ?TransactionResponse {.base, contract.}
|
||||
@ -108,8 +107,8 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
||||
let signer0 = provider.getSigner(accounts[0])
|
||||
let signer1 = provider.getSigner(accounts[1])
|
||||
discard await token.connect(signer0).mint(accounts[0], 100.u256)
|
||||
await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||
await token.connect(signer1).transfer(accounts[2], 25.u256)
|
||||
discard await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||
discard await token.connect(signer1).transfer(accounts[2], 25.u256)
|
||||
check (await token.connect(provider).balanceOf(accounts[0])) == 50.u256
|
||||
check (await token.connect(provider).balanceOf(accounts[1])) == 25.u256
|
||||
check (await token.connect(provider).balanceOf(accounts[2])) == 25.u256
|
||||
@ -150,8 +149,8 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
||||
|
||||
let subscription = await token.subscribe(Transfer, handleTransfer)
|
||||
discard await token.connect(signer0).mint(accounts[0], 100.u256)
|
||||
await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||
await token.connect(signer1).transfer(accounts[2], 25.u256)
|
||||
discard await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||
discard await token.connect(signer1).transfer(accounts[2], 25.u256)
|
||||
|
||||
check eventually transfers == @[
|
||||
Transfer(receiver: accounts[0], value: 100.u256),
|
||||
@ -175,7 +174,7 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
||||
check eventually transfers.len == 1
|
||||
await subscription.unsubscribe()
|
||||
|
||||
await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||
discard await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||
await sleepAsync(100.millis)
|
||||
|
||||
check transfers.len == 1
|
||||
|
@ -51,7 +51,7 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||
|
||||
await token.transfer(accounts[1], 50.u256)
|
||||
discard await token.transfer(accounts[1], 50.u256)
|
||||
|
||||
check (await token.balanceOf(accounts[0])) == 50.u256
|
||||
check (await token.balanceOf(accounts[1])) == 50.u256
|
||||
@ -63,7 +63,7 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||
|
||||
await token.approve(accounts[1], 50.u256)
|
||||
discard await token.approve(accounts[1], 50.u256)
|
||||
|
||||
check (await token.allowance(accounts[0], accounts[1])) == 50.u256
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
@ -83,13 +83,13 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
||||
check (await token.balanceOf(senderAccount)) == 100.u256
|
||||
check (await token.balanceOf(receiverAccount)) == 0.u256
|
||||
|
||||
await token.approve(receiverAccount, 50.u256)
|
||||
discard await token.approve(receiverAccount, 50.u256)
|
||||
|
||||
check (await token.allowance(senderAccount, receiverAccount)) == 50.u256
|
||||
check (await token.balanceOf(senderAccount)) == 100.u256
|
||||
check (await token.balanceOf(receiverAccount)) == 0.u256
|
||||
|
||||
await token.connect(receiverAccountSigner).transferFrom(senderAccount, receiverAccount, 50.u256)
|
||||
discard await token.connect(receiverAccountSigner).transferFrom(senderAccount, receiverAccount, 50.u256)
|
||||
|
||||
check (await token.balanceOf(senderAccount)) == 50.u256
|
||||
check (await token.balanceOf(receiverAccount)) == 50.u256
|
||||
|
Loading…
x
Reference in New Issue
Block a user