Add ERC6909 Implementation along with extensions (#5394)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Ernesto García <ernestognw@gmail.com>
This commit is contained in:
49
test/token/ERC6909/extensions/ERC6909ContentURI.test.js
Normal file
49
test/token/ERC6909/extensions/ERC6909ContentURI.test.js
Normal file
@ -0,0 +1,49 @@
|
||||
const { ethers } = require('hardhat');
|
||||
const { expect } = require('chai');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
async function fixture() {
|
||||
const token = await ethers.deployContract('$ERC6909ContentURI');
|
||||
return { token };
|
||||
}
|
||||
|
||||
describe('ERC6909ContentURI', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
describe('contractURI', function () {
|
||||
it('is empty string be default', async function () {
|
||||
await expect(this.token.contractURI()).to.eventually.equal('');
|
||||
});
|
||||
|
||||
it('is settable by internal setter', async function () {
|
||||
await this.token.$_setContractURI('https://example.com');
|
||||
await expect(this.token.contractURI()).to.eventually.equal('https://example.com');
|
||||
});
|
||||
|
||||
it('emits an event when set', async function () {
|
||||
await expect(this.token.$_setContractURI('https://example.com')).to.emit(this.token, 'ContractURIUpdated');
|
||||
});
|
||||
});
|
||||
|
||||
describe('tokenURI', function () {
|
||||
it('is empty string be default', async function () {
|
||||
await expect(this.token.tokenURI(1n)).to.eventually.equal('');
|
||||
});
|
||||
|
||||
it('can be set by dedicated setter', async function () {
|
||||
await this.token.$_setTokenURI(1n, 'https://example.com/1');
|
||||
await expect(this.token.tokenURI(1n)).to.eventually.equal('https://example.com/1');
|
||||
|
||||
// Only set for the specified token ID
|
||||
await expect(this.token.tokenURI(2n)).to.eventually.equal('');
|
||||
});
|
||||
|
||||
it('emits an event when set', async function () {
|
||||
await expect(this.token.$_setTokenURI(1n, 'https://example.com/1'))
|
||||
.to.emit(this.token, 'URI')
|
||||
.withArgs('https://example.com/1', 1n);
|
||||
});
|
||||
});
|
||||
});
|
||||
58
test/token/ERC6909/extensions/ERC6909Metadata.test.js
Normal file
58
test/token/ERC6909/extensions/ERC6909Metadata.test.js
Normal file
@ -0,0 +1,58 @@
|
||||
const { ethers } = require('hardhat');
|
||||
const { expect } = require('chai');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
async function fixture() {
|
||||
const token = await ethers.deployContract('$ERC6909Metadata');
|
||||
return { token };
|
||||
}
|
||||
|
||||
describe('ERC6909Metadata', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
describe('name', function () {
|
||||
it('is empty string be default', async function () {
|
||||
await expect(this.token.name(1n)).to.eventually.equal('');
|
||||
});
|
||||
|
||||
it('can be set by dedicated setter', async function () {
|
||||
await expect(this.token.$_setName(1n, 'My Token'))
|
||||
.to.emit(this.token, 'ERC6909NameUpdated')
|
||||
.withArgs(1n, 'My Token');
|
||||
await expect(this.token.name(1n)).to.eventually.equal('My Token');
|
||||
|
||||
// Only set for the specified token ID
|
||||
await expect(this.token.name(2n)).to.eventually.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('symbol', function () {
|
||||
it('is empty string be default', async function () {
|
||||
await expect(this.token.symbol(1n)).to.eventually.equal('');
|
||||
});
|
||||
|
||||
it('can be set by dedicated setter', async function () {
|
||||
await expect(this.token.$_setSymbol(1n, 'MTK')).to.emit(this.token, 'ERC6909SymbolUpdated').withArgs(1n, 'MTK');
|
||||
await expect(this.token.symbol(1n)).to.eventually.equal('MTK');
|
||||
|
||||
// Only set for the specified token ID
|
||||
await expect(this.token.symbol(2n)).to.eventually.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decimals', function () {
|
||||
it('is 0 by default', async function () {
|
||||
await expect(this.token.decimals(1n)).to.eventually.equal(0);
|
||||
});
|
||||
|
||||
it('can be set by dedicated setter', async function () {
|
||||
await expect(this.token.$_setDecimals(1n, 18)).to.emit(this.token, 'ERC6909DecimalsUpdated').withArgs(1n, 18);
|
||||
await expect(this.token.decimals(1n)).to.eventually.equal(18);
|
||||
|
||||
// Only set for the specified token ID
|
||||
await expect(this.token.decimals(2n)).to.eventually.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
53
test/token/ERC6909/extensions/ERC6909TokenSupply.test.js
Normal file
53
test/token/ERC6909/extensions/ERC6909TokenSupply.test.js
Normal file
@ -0,0 +1,53 @@
|
||||
const { ethers } = require('hardhat');
|
||||
const { expect } = require('chai');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const { shouldBehaveLikeERC6909 } = require('../ERC6909.behavior');
|
||||
|
||||
async function fixture() {
|
||||
const [holder, operator, recipient, other] = await ethers.getSigners();
|
||||
const token = await ethers.deployContract('$ERC6909TokenSupply');
|
||||
return { token, holder, operator, recipient, other };
|
||||
}
|
||||
|
||||
describe('ERC6909TokenSupply', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
shouldBehaveLikeERC6909();
|
||||
|
||||
describe('totalSupply', function () {
|
||||
it('is zero before any mint', async function () {
|
||||
await expect(this.token.totalSupply(1n)).to.eventually.be.equal(0n);
|
||||
});
|
||||
|
||||
it('minting tokens increases the total supply', async function () {
|
||||
await this.token.$_mint(this.holder, 1n, 17n);
|
||||
await expect(this.token.totalSupply(1n)).to.eventually.be.equal(17n);
|
||||
});
|
||||
|
||||
describe('with tokens minted', function () {
|
||||
const supply = 1000n;
|
||||
|
||||
beforeEach(async function () {
|
||||
await this.token.$_mint(this.holder, 1n, supply);
|
||||
});
|
||||
|
||||
it('burning tokens decreases the total supply', async function () {
|
||||
await this.token.$_burn(this.holder, 1n, 17n);
|
||||
await expect(this.token.totalSupply(1n)).to.eventually.be.equal(supply - 17n);
|
||||
});
|
||||
|
||||
it('supply unaffected by transfers', async function () {
|
||||
await this.token.$_transfer(this.holder, this.recipient, 1n, 42n);
|
||||
await expect(this.token.totalSupply(1n)).to.eventually.be.equal(supply);
|
||||
});
|
||||
|
||||
it('supply unaffected by no-op', async function () {
|
||||
await this.token.$_update(ethers.ZeroAddress, ethers.ZeroAddress, 1n, 42n);
|
||||
await expect(this.token.totalSupply(1n)).to.eventually.be.equal(supply);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user