mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-01-23 14:00:32 +00:00
feat: (de/in)crease allowance (#56)
This commit is contained in:
parent
f0303473f6
commit
620b402a7d
@ -54,6 +54,24 @@ method approve*(token: Erc20Token,
|
||||
amount: UInt256): ?TransactionResponse {.base, contract.}
|
||||
## Sets `amount` as the allowance of `spender` over the caller's tokens.
|
||||
|
||||
method increaseAllowance*(token: Erc20Token,
|
||||
spender: Address,
|
||||
addedValue: UInt256): ?TransactionResponse {.base, contract.}
|
||||
## Atomically increases the allowance granted to spender by the caller.
|
||||
## This is an alternative to approve that can be used as a mitigation for problems described in IERC20.approve.
|
||||
## Emits an Approval event indicating the updated allowance.
|
||||
##
|
||||
## WARNING: THIS IS NON-STANDARD ERC-20 FUNCTION, DOUBLE CHECK THAT YOUR TOKEN HAS IT!
|
||||
|
||||
method decreaseAllowance*(token: Erc20Token,
|
||||
spender: Address,
|
||||
addedValue: UInt256): ?TransactionResponse {.base, contract.}
|
||||
## Atomically decreases the allowance granted to spender by the caller.
|
||||
## This is an alternative to approve that can be used as a mitigation for problems described in IERC20.approve.
|
||||
## Emits an Approval event indicating the updated allowance.
|
||||
##
|
||||
## WARNING: THIS IS NON-STANDARD ERC-20 FUNCTION, DOUBLE CHECK THAT YOUR TOKEN HAS IT!
|
||||
|
||||
method transferFrom*(token: Erc20Token,
|
||||
spender: Address,
|
||||
recipient: Address,
|
||||
|
@ -69,6 +69,32 @@ 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
|
||||
|
||||
test "increase/decrease allowance":
|
||||
discard await testToken.mint(accounts[0], 100.u256)
|
||||
|
||||
check (await token.allowance(accounts[0], accounts[1])) == 0.u256
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||
|
||||
discard await token.increaseAllowance(accounts[1], 50.u256)
|
||||
|
||||
check (await token.allowance(accounts[0], accounts[1])) == 50.u256
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||
|
||||
discard await token.increaseAllowance(accounts[1], 50.u256)
|
||||
|
||||
check (await token.allowance(accounts[0], accounts[1])) == 100.u256
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||
|
||||
discard await token.decreaseAllowance(accounts[1], 50.u256)
|
||||
|
||||
check (await token.allowance(accounts[0], accounts[1])) == 50.u256
|
||||
check (await token.balanceOf(accounts[0])) == 100.u256
|
||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||
|
||||
|
||||
test "transferFrom tokens":
|
||||
let senderAccount = accounts[0]
|
||||
let receiverAccount = accounts[1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user