-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from invariant-labs/sdk-erc20-tests
refactor erc20 class and add erc20 tests to sdk
- Loading branch information
Showing
4 changed files
with
94 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
testTimeout: 20000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,69 @@ | ||
import { ALICE, LOCAL_NODE_URL } from '../src/consts' | ||
import { Network } from '../src/enums' | ||
import { ALICE, BOB, LOCAL_NODE_URL } from '../src/consts' | ||
import { Key, Network } from '../src/enums' | ||
import { Erc20 } from '../src/erc20' | ||
import { initCasperClientAndService } from '../src/utils' | ||
|
||
describe('erc20', () => { | ||
it('should get metadata', async () => { | ||
const { client, service } = initCasperClientAndService(LOCAL_NODE_URL) | ||
const { client, service } = initCasperClientAndService(LOCAL_NODE_URL) | ||
let erc20: Erc20 | ||
const aliceAddress = ALICE.publicKey.toAccountHashStr().replace('account-hash-', '') | ||
const bobAddress = BOB.publicKey.toAccountHashStr().replace('account-hash-', '') | ||
|
||
const [, erc20Hash] = await Erc20.deploy( | ||
describe('erc20', () => { | ||
beforeEach(async () => { | ||
const [, erc20ContractHash] = await Erc20.deploy( | ||
client, | ||
service, | ||
Network.Local, | ||
ALICE, | ||
'0', | ||
1000000000000n, | ||
'erc20', | ||
1000n, | ||
'Coin', | ||
'COIN', | ||
6n, | ||
12n, | ||
150000000000n | ||
) | ||
|
||
const erc20 = await Erc20.load(client, service, erc20Hash) | ||
erc20 = await Erc20.load(client, service, Network.Local, erc20ContractHash) | ||
}) | ||
|
||
it('should set metadata', async () => { | ||
expect(await erc20.name()).toEqual('Coin') | ||
expect(await erc20.symbol()).toEqual('COIN') | ||
expect(await erc20.decimals()).toEqual(6n) | ||
expect(await erc20.decimals()).toEqual(12n) | ||
}) | ||
|
||
it('should mint tokens', async () => { | ||
await erc20.mint(ALICE, Key.Account, aliceAddress, 500n) | ||
expect(await erc20.balanceOf(Key.Account, aliceAddress)).toEqual(1500n) | ||
}) | ||
|
||
it('should transfer tokens', async () => { | ||
await erc20.transfer(ALICE, Key.Account, bobAddress, 250n) | ||
expect(await erc20.balanceOf(Key.Account, aliceAddress)).toEqual(750n) | ||
expect(await erc20.balanceOf(Key.Account, bobAddress)).toEqual(250n) | ||
}) | ||
|
||
it('should change instance', async () => { | ||
const [, erc20ContractHash] = await Erc20.deploy( | ||
client, | ||
service, | ||
Network.Local, | ||
ALICE, | ||
'erc20', | ||
1000n, | ||
'Coin', | ||
'COIN', | ||
12n, | ||
150000000000n | ||
) | ||
|
||
await erc20.transfer(ALICE, Key.Account, bobAddress, 250n) | ||
erc20.setContractHash(erc20ContractHash) | ||
expect(await erc20.balanceOf(Key.Account, aliceAddress)).toEqual(1000n) | ||
}) | ||
|
||
it('should approve tokens', async () => { | ||
await erc20.approve(ALICE, Key.Account, bobAddress, 250n) | ||
expect(await erc20.allowance(Key.Account, aliceAddress, Key.Account, bobAddress)).toEqual(250n) | ||
}) | ||
}) |