aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test/utils/token_utils.ts
blob: 0a35b4107047a9e3707f0f97832fb4880e37c57b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { artifacts, wrappers } from '@0xproject/contracts';
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils';

import { constants } from './constants';
import { provider, txDefaults, web3Wrapper } from './web3_wrapper';

// Those addresses come from migrations. They're deterministic so it's relatively safe to hard-code them here.
// Before we were fetching them from the TokenRegistry but now we can't as it's deprecated and removed.
const DUMMY_ERC_20_ADRESSES = [
    '0x6dfff22588be9b3ef8cf0ad6dc9b84796f9fb45f',
    '0xcfc18cec799fbd1793b5c43e773c98d4d61cc2db',
    '0xf22469f31527adc53284441bae1665a7b9214dba',
    '0x10add991de718a69dec2117cb6aa28098836511b',
    '0x8d61158a366019ac78db4149d75fff9dda51160d',
];

const DUMMY_ERC_721_ADRESSES = ['0x131855dda0aaff096f6854854c55a4debf61077a'];

export const tokenUtils = {
    getProtocolTokenAddress(): string {
        return artifacts.ZRXToken.networks[constants.TESTRPC_NETWORK_ID].address;
    },
    getWethTokenAddress(): string {
        return artifacts.WETH9.networks[constants.TESTRPC_NETWORK_ID].address;
    },
    getDummyERC20TokenAddresses(): string[] {
        return DUMMY_ERC_20_ADRESSES;
    },
    getDummyERC721TokenAddresses(): string[] {
        return DUMMY_ERC_721_ADRESSES;
    },
    async mintDummyERC721Async(address: string, tokenOwner: string): Promise<BigNumber> {
        const erc721 = new wrappers.DummyERC721TokenContract(
            artifacts.DummyERC721Token.compilerOutput.abi,
            address,
            provider,
            txDefaults,
        );
        const tokenId = generatePseudoRandomSalt();
        const txHash = await erc721.mint.sendTransactionAsync(tokenOwner, tokenId);
        web3Wrapper.awaitTransactionSuccessAsync(txHash);
        return tokenId;
    },
};