This repository has been archived by the owner on Jan 29, 2021. It is now read-only.
/
ChildArt.test.js
130 lines (106 loc) · 4.37 KB
/
ChildArt.test.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiBigNumber from 'chai-bignumber';
import { assertRevert } from 'openzeppelin-solidity/test/helpers/assertRevert';
import { ether } from 'openzeppelin-solidity/test/helpers/ether';
chai.use(chaiBigNumber());
chai.use(chaiAsPromised);
const { expect, assert } = chai;
const ChildArt = artifacts.require('ChildArt');
contract('ChildArtTest', async (accounts) => {
let instance;
let owner;
beforeEach(async () => {
instance = await ChildArt.deployed();
owner = await instance.owner();
await instance.setPaperFee(0);
const balance = await instance.getBalanceContract();
if (balance.gt(0)) {
await instance.withdraw(balance);
}
});
it('Should make first account an owner', async () => {
expect(owner).to.equal(accounts[0]);
});
describe('mintPaper', () => {
context('without fee', () => {
it('creates token with tokenURI', async () => {
const imageHash = 'test';
const ipfsUri = 'https://gateway.ipfs.io/ipfs/test';
await instance.mintPaper(imageHash, ipfsUri);
const tokenId = await instance.tokenOfOwnerByIndex(owner, 0);
const tokenUri = await instance.tokenURI(tokenId);
expect(tokenUri).to.equal(ipfsUri);
});
it('should be unique', async () => {
const imageHash = 'uniq';
const ipfsUri = 'https://gateway.ipfs.io/ipfs/test';
await instance.mintPaper(imageHash, ipfsUri);
await assertRevert(instance.mintPaper(imageHash, ipfsUri, { from: accounts[1] }));
});
});
context('require fee', () => {
it('rejects without fee', async () => {
await instance.setPaperFee(ether(0.1));
const imageHash = 'fee_test';
const ipfsUri = 'https://gateway.ipfs.io/ipfs/test';
await assertRevert(instance.mintPaper(imageHash, ipfsUri));
});
it('creates token by fee', async () => {
await instance.setPaperFee(ether(0.1));
const imageHash = 'fee_test';
const ipfsUri = 'https://gateway.ipfs.io/ipfs/test';
await instance.mintPaper(imageHash, ipfsUri, { value: ether(0.1) }).should.be.fulfilled;
});
});
});
describe('tokenIdByIpfsHash', () => {
it('gets tokenId', async () => {
const imageHash = 'hash_test';
const ipfsUri = 'https://gateway.ipfs.io/ipfs/test';
await instance.mintPaper(imageHash, ipfsUri).should.be.fulfilled;
const totalSupply = await instance.totalSupply();
const tokenId = await instance.tokenIdByIpfsHash(imageHash);
expect(tokenId).to.bignumber.equal(totalSupply);
});
it('throws error if not exist', async () => {
await assertRevert(instance.tokenIdByIpfsHash('ipfs_hash'));
});
});
describe('getPaperFee', () => {
it('gets paperFee', async () => {
const paperFee = await instance.getPaperFee();
expect(paperFee).to.bignumber.equal(0);
});
});
describe('setPaperFee', () => {
it('sets paperFee', async () => {
const beforePaperFee = await instance.getPaperFee();
expect(beforePaperFee).to.bignumber.equal(0);
await instance.setPaperFee(ether(0.1));
const afterPaperFee = await instance.getPaperFee();
expect(afterPaperFee).to.bignumber.equal(ether(0.1));
});
});
describe('getBalanceContract', () => {
it('gets balance', async () => {
await instance.setPaperFee(ether(1));
await instance.mintPaper('balance', 'https://gateway.ipfs.io/ipfs/test', { value: ether(1) }).should.be.fulfilled;
const balance = await instance.getBalanceContract();
expect(balance).to.bignumber.equal(ether(1));
});
});
describe('withdraw', () => {
it('withdraws only owner', async () => {
await instance.setPaperFee(ether(1));
await instance.mintPaper('balance1', 'https://gateway.ipfs.io/ipfs/test', { value: ether(1) }).should.be.fulfilled;
await instance.mintPaper('balance2', 'https://gateway.ipfs.io/ipfs/test', { value: ether(1) }).should.be.fulfilled;
await instance.withdraw(ether(2)).should.be.fulfilled;
});
it('should not withdraws other account', async () => {
await instance.setPaperFee(ether(1));
await instance.mintPaper('balance3', 'https://gateway.ipfs.io/ipfs/test', { value: ether(1) }).should.be.fulfilled;
await assertRevert(instance.withdraw(ether(1), { from: accounts[1] }));
});
});
});