-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy patherc1155-ownable.spec.ts
106 lines (92 loc) · 3.41 KB
/
erc1155-ownable.spec.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import {
defaultWeb3Connection,
getPrivateKeyFromFile,
shouldBeRejected,
} from '../utils';
import { ERC1155Ownable, Web3Connection } from '../../src';
import { expect } from 'chai';
import { Account } from 'web3-core';
describe(`ERC1155 Ownable`, () => {
let contract: ERC1155Ownable;
let web3Connection: Web3Connection;
let contractAddress: string;
let bob: Account;
let alice: Account;
const initial = {
uri: 'https://my.token.uri',
};
before(async () => {
web3Connection = await defaultWeb3Connection(true, true);
bob = web3Connection.Web3.eth.accounts.privateKeyToAccount(
getPrivateKeyFromFile(1)
);
alice = web3Connection.Web3.eth.accounts.privateKeyToAccount(
getPrivateKeyFromFile(0)
);
});
it(`Deploys the contract`, async () => {
const deployer = new ERC1155Ownable(web3Connection);
deployer.loadAbi();
const tx = await deployer.deployJsonAbi('https://my.token.uri');
expect(tx.blockNumber).to.exist;
contractAddress = tx.contractAddress!;
});
describe(`Methods`, () => {
before(async () => {
contract = new ERC1155Ownable(web3Connection, contractAddress!);
await contract.start();
});
it(`Set a new URI for all tokens`, async () => {
const uriBeforeSetting = await contract.uri(0);
await contract.setURI('https://domain.tld/');
const uriAfterSetting = await contract.uri(0);
expect(uriBeforeSetting).to.have.string(initial.uri);
expect(uriAfterSetting).to.have.string('https://domain.tld/');
});
it(`mints the token id`, async () => {
await contract.mint(bob.address, 0, 100, '0x12345678');
expect(await contract.balanceOf(bob.address, 0)).to.be.eq(100);
});
it(`mints a bunch of token ids`, async () => {
const tokenIds = [123, 212, 344];
const amounts = [100, 200, 300];
await contract.mintBatch(bob.address, tokenIds, amounts, '0x12345678');
const expectedAmounts = await contract.balanceOfBatch(
[bob.address, bob.address, bob.address],
tokenIds
);
expect(expectedAmounts[0]).to.be.eq(amounts[0]);
expect(expectedAmounts[1]).to.be.eq(amounts[1]);
expect(expectedAmounts[2]).to.be.eq(amounts[2]);
});
describe('Account address different from owner', () => {
before(async () => {
contract.connection.switchToAccount(bob.privateKey);
});
it(`'setURI' reverts the transaction: OR => OwnerRequired`, async () => {
const uriBeforeSetting = await contract.uri(0);
await shouldBeRejected(contract.setURI('https://bob.domain/'), 'OR');
expect(uriBeforeSetting).to.have.string(await contract.uri(0));
});
it(`'mint' reverts the transaction: OR => OwnerRequired`, async () => {
await shouldBeRejected(
contract.mint(alice.address, 0, 100, '0x12345678'),
'OR'
);
expect(await contract.balanceOf(alice.address, 0)).to.not.eq(100);
});
it(`'mintBatch' reverts the transaction: OR => OwnerRequired`, async () => {
await shouldBeRejected(
contract.mintBatch(alice.address, [0, 1], [500, 600], '0x12345678'),
'OR'
);
const expectedAmounts = await contract.balanceOfBatch(
[alice.address, alice.address],
[0, 1]
);
expect(expectedAmounts[0]).to.not.eq(500);
expect(expectedAmounts[1]).to.not.eq(600);
});
});
});
});