Skip to content

Commit 9b0d11d

Browse files
committed
improving approval test
1 parent 2f59022 commit 9b0d11d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/arc.spec.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Address,
99
Arc,
1010
Plugin,
11-
REDEEMER_CONTRACT_VERSIONS
11+
REDEEMER_CONTRACT_VERSIONS,
12+
Token
1213
} from '../src/index'
1314
import {
1415
fromWei,
@@ -318,12 +319,22 @@ it('plugin contractInfo should contain alias', async () => {
318319
expect(contractInfo.alias).toEqual("ContributionRewardExt")
319320
})
320321

321-
it('arc.approveToken should return tx with status one', async () => {
322+
it.only('arc.approveToken should return tx with status one', async () => {
322323
const arc = await newArc()
323324
const addresses = getTestAddresses()
324325
const tokenAddress = addresses.dao.DAOToken
325-
const account = '0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1'
326-
const approval = await arc.approveTokens(tokenAddress, account, new BN(1)).send();
326+
const spender = '0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1'
327+
const amount = toWei('31415')
328+
const approval = await arc.approveTokens(tokenAddress, spender, amount).send();
327329
expect(approval.transactionHash).toBeDefined();
328330
expect(approval.receipt!.status).toEqual(1);
331+
const token = new Token(arc, tokenAddress);
332+
const signer = (arc.web3 as JsonRpcProvider).getSigner(arc.defaultAccount as any)
333+
const allowances: Array<BN> = []
334+
const lastAllowance = () => allowances[allowances.length - 1]
335+
await token.allowance(await signer.getAddress(), spender).subscribe(
336+
(next: any) => allowances.push(next)
337+
)
338+
await waitUntilTrue(() => allowances.length > 0 && lastAllowance().gte(amount))
339+
expect(lastAllowance()).toMatchObject(amount)
329340
})

0 commit comments

Comments
 (0)