Implement recommendations from 5.0 audit Phase 1A (#4398)
Co-authored-by: Francisco Giordano <fg@frang.io> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -21,19 +21,19 @@ contract('ERC1155', function (accounts) {
|
||||
|
||||
describe('internal functions', function () {
|
||||
const tokenId = new BN(1990);
|
||||
const mintAmount = new BN(9001);
|
||||
const burnAmount = new BN(3000);
|
||||
const mintValue = new BN(9001);
|
||||
const burnValue = new BN(3000);
|
||||
|
||||
const tokenBatchIds = [new BN(2000), new BN(2010), new BN(2020)];
|
||||
const mintAmounts = [new BN(5000), new BN(10000), new BN(42195)];
|
||||
const burnAmounts = [new BN(5000), new BN(9001), new BN(195)];
|
||||
const mintValues = [new BN(5000), new BN(10000), new BN(42195)];
|
||||
const burnValues = [new BN(5000), new BN(9001), new BN(195)];
|
||||
|
||||
const data = '0x12345678';
|
||||
|
||||
describe('_mint', function () {
|
||||
it('reverts with a zero destination address', async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_mint(ZERO_ADDRESS, tokenId, mintAmount, data),
|
||||
this.token.$_mint(ZERO_ADDRESS, tokenId, mintValue, data),
|
||||
'ERC1155InvalidReceiver',
|
||||
[ZERO_ADDRESS],
|
||||
);
|
||||
@ -41,7 +41,7 @@ contract('ERC1155', function (accounts) {
|
||||
|
||||
context('with minted tokens', function () {
|
||||
beforeEach(async function () {
|
||||
this.receipt = await this.token.$_mint(tokenHolder, tokenId, mintAmount, data, { from: operator });
|
||||
this.receipt = await this.token.$_mint(tokenHolder, tokenId, mintValue, data, { from: operator });
|
||||
});
|
||||
|
||||
it('emits a TransferSingle event', function () {
|
||||
@ -50,12 +50,12 @@ contract('ERC1155', function (accounts) {
|
||||
from: ZERO_ADDRESS,
|
||||
to: tokenHolder,
|
||||
id: tokenId,
|
||||
value: mintAmount,
|
||||
value: mintValue,
|
||||
});
|
||||
});
|
||||
|
||||
it('credits the minted amount of tokens', async function () {
|
||||
expect(await this.token.balanceOf(tokenHolder, tokenId)).to.be.bignumber.equal(mintAmount);
|
||||
it('credits the minted token value', async function () {
|
||||
expect(await this.token.balanceOf(tokenHolder, tokenId)).to.be.bignumber.equal(mintValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -63,7 +63,7 @@ contract('ERC1155', function (accounts) {
|
||||
describe('_mintBatch', function () {
|
||||
it('reverts with a zero destination address', async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_mintBatch(ZERO_ADDRESS, tokenBatchIds, mintAmounts, data),
|
||||
this.token.$_mintBatch(ZERO_ADDRESS, tokenBatchIds, mintValues, data),
|
||||
'ERC1155InvalidReceiver',
|
||||
[ZERO_ADDRESS],
|
||||
);
|
||||
@ -71,21 +71,21 @@ contract('ERC1155', function (accounts) {
|
||||
|
||||
it('reverts if length of inputs do not match', async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds, mintAmounts.slice(1), data),
|
||||
this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds, mintValues.slice(1), data),
|
||||
'ERC1155InvalidArrayLength',
|
||||
[tokenBatchIds.length, mintAmounts.length - 1],
|
||||
[tokenBatchIds.length, mintValues.length - 1],
|
||||
);
|
||||
|
||||
await expectRevertCustomError(
|
||||
this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds.slice(1), mintAmounts, data),
|
||||
this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds.slice(1), mintValues, data),
|
||||
'ERC1155InvalidArrayLength',
|
||||
[tokenBatchIds.length - 1, mintAmounts.length],
|
||||
[tokenBatchIds.length - 1, mintValues.length],
|
||||
);
|
||||
});
|
||||
|
||||
context('with minted batch of tokens', function () {
|
||||
beforeEach(async function () {
|
||||
this.receipt = await this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds, mintAmounts, data, {
|
||||
this.receipt = await this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds, mintValues, data, {
|
||||
from: operator,
|
||||
});
|
||||
});
|
||||
@ -105,7 +105,7 @@ contract('ERC1155', function (accounts) {
|
||||
);
|
||||
|
||||
for (let i = 0; i < holderBatchBalances.length; i++) {
|
||||
expect(holderBatchBalances[i]).to.be.bignumber.equal(mintAmounts[i]);
|
||||
expect(holderBatchBalances[i]).to.be.bignumber.equal(mintValues[i]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -113,33 +113,33 @@ contract('ERC1155', function (accounts) {
|
||||
|
||||
describe('_burn', function () {
|
||||
it("reverts when burning the zero account's tokens", async function () {
|
||||
await expectRevertCustomError(this.token.$_burn(ZERO_ADDRESS, tokenId, mintAmount), 'ERC1155InvalidSender', [
|
||||
await expectRevertCustomError(this.token.$_burn(ZERO_ADDRESS, tokenId, mintValue), 'ERC1155InvalidSender', [
|
||||
ZERO_ADDRESS,
|
||||
]);
|
||||
});
|
||||
|
||||
it('reverts when burning a non-existent token id', async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_burn(tokenHolder, tokenId, mintAmount),
|
||||
this.token.$_burn(tokenHolder, tokenId, mintValue),
|
||||
'ERC1155InsufficientBalance',
|
||||
[tokenHolder, 0, mintAmount, tokenId],
|
||||
[tokenHolder, 0, mintValue, tokenId],
|
||||
);
|
||||
});
|
||||
|
||||
it('reverts when burning more than available tokens', async function () {
|
||||
await this.token.$_mint(tokenHolder, tokenId, mintAmount, data, { from: operator });
|
||||
await this.token.$_mint(tokenHolder, tokenId, mintValue, data, { from: operator });
|
||||
|
||||
await expectRevertCustomError(
|
||||
this.token.$_burn(tokenHolder, tokenId, mintAmount.addn(1)),
|
||||
this.token.$_burn(tokenHolder, tokenId, mintValue.addn(1)),
|
||||
'ERC1155InsufficientBalance',
|
||||
[tokenHolder, mintAmount, mintAmount.addn(1), tokenId],
|
||||
[tokenHolder, mintValue, mintValue.addn(1), tokenId],
|
||||
);
|
||||
});
|
||||
|
||||
context('with minted-then-burnt tokens', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.$_mint(tokenHolder, tokenId, mintAmount, data);
|
||||
this.receipt = await this.token.$_burn(tokenHolder, tokenId, burnAmount, { from: operator });
|
||||
await this.token.$_mint(tokenHolder, tokenId, mintValue, data);
|
||||
this.receipt = await this.token.$_burn(tokenHolder, tokenId, burnValue, { from: operator });
|
||||
});
|
||||
|
||||
it('emits a TransferSingle event', function () {
|
||||
@ -148,12 +148,12 @@ contract('ERC1155', function (accounts) {
|
||||
from: tokenHolder,
|
||||
to: ZERO_ADDRESS,
|
||||
id: tokenId,
|
||||
value: burnAmount,
|
||||
value: burnValue,
|
||||
});
|
||||
});
|
||||
|
||||
it('accounts for both minting and burning', async function () {
|
||||
expect(await this.token.balanceOf(tokenHolder, tokenId)).to.be.bignumber.equal(mintAmount.sub(burnAmount));
|
||||
expect(await this.token.balanceOf(tokenHolder, tokenId)).to.be.bignumber.equal(mintValue.sub(burnValue));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -161,7 +161,7 @@ contract('ERC1155', function (accounts) {
|
||||
describe('_burnBatch', function () {
|
||||
it("reverts when burning the zero account's tokens", async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_burnBatch(ZERO_ADDRESS, tokenBatchIds, burnAmounts),
|
||||
this.token.$_burnBatch(ZERO_ADDRESS, tokenBatchIds, burnValues),
|
||||
'ERC1155InvalidSender',
|
||||
[ZERO_ADDRESS],
|
||||
);
|
||||
@ -169,30 +169,30 @@ contract('ERC1155', function (accounts) {
|
||||
|
||||
it('reverts if length of inputs do not match', async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds, burnAmounts.slice(1)),
|
||||
this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds, burnValues.slice(1)),
|
||||
'ERC1155InvalidArrayLength',
|
||||
[tokenBatchIds.length, burnAmounts.length - 1],
|
||||
[tokenBatchIds.length, burnValues.length - 1],
|
||||
);
|
||||
|
||||
await expectRevertCustomError(
|
||||
this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds.slice(1), burnAmounts),
|
||||
this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds.slice(1), burnValues),
|
||||
'ERC1155InvalidArrayLength',
|
||||
[tokenBatchIds.length - 1, burnAmounts.length],
|
||||
[tokenBatchIds.length - 1, burnValues.length],
|
||||
);
|
||||
});
|
||||
|
||||
it('reverts when burning a non-existent token id', async function () {
|
||||
await expectRevertCustomError(
|
||||
this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds, burnAmounts),
|
||||
this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds, burnValues),
|
||||
'ERC1155InsufficientBalance',
|
||||
[tokenBatchHolder, 0, tokenBatchIds[0], burnAmounts[0]],
|
||||
[tokenBatchHolder, 0, tokenBatchIds[0], burnValues[0]],
|
||||
);
|
||||
});
|
||||
|
||||
context('with minted-then-burnt tokens', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds, mintAmounts, data);
|
||||
this.receipt = await this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds, burnAmounts, { from: operator });
|
||||
await this.token.$_mintBatch(tokenBatchHolder, tokenBatchIds, mintValues, data);
|
||||
this.receipt = await this.token.$_burnBatch(tokenBatchHolder, tokenBatchIds, burnValues, { from: operator });
|
||||
});
|
||||
|
||||
it('emits a TransferBatch event', function () {
|
||||
@ -201,7 +201,7 @@ contract('ERC1155', function (accounts) {
|
||||
from: tokenBatchHolder,
|
||||
to: ZERO_ADDRESS,
|
||||
// ids: tokenBatchIds,
|
||||
// values: burnAmounts,
|
||||
// values: burnValues,
|
||||
});
|
||||
});
|
||||
|
||||
@ -212,7 +212,7 @@ contract('ERC1155', function (accounts) {
|
||||
);
|
||||
|
||||
for (let i = 0; i < holderBatchBalances.length; i++) {
|
||||
expect(holderBatchBalances[i]).to.be.bignumber.equal(mintAmounts[i].sub(burnAmounts[i]));
|
||||
expect(holderBatchBalances[i]).to.be.bignumber.equal(mintValues[i].sub(burnValues[i]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user