-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rewrite_delete
- Loading branch information
Showing
8 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
// ERC721A Contracts v4.0.0 | ||
// Creators: Chiru Labs | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import './ERC721AMock.sol'; | ||
|
||
contract ERC721ATransferCounterMock is ERC721AMock { | ||
constructor(string memory name_, string memory symbol_) ERC721AMock(name_, symbol_) {} | ||
|
||
function _extraData( | ||
address from, | ||
address to, | ||
uint24 previousExtraData | ||
) internal view virtual override returns (uint24) { | ||
if (from == address(0)) { | ||
return 42; | ||
} | ||
if (to == address(0)) { | ||
return 1337; | ||
} | ||
return previousExtraData + 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
// ERC721A Contracts v4.0.0 | ||
// Creators: Chiru Labs | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import '../ERC721A.sol'; | ||
|
||
contract ERC721AWithERC2309Mock is ERC721A { | ||
constructor( | ||
string memory name_, | ||
string memory symbol_, | ||
address to, | ||
uint256 quantity, | ||
bool mintInConstructor | ||
) ERC721A(name_, symbol_) { | ||
if (mintInConstructor) { | ||
_mintERC2309(to, quantity); | ||
} | ||
} | ||
|
||
/** | ||
* @dev This function is only for gas comparison purposes. | ||
* Calling `_mintERC3201` outside of contract creation is non-compliant | ||
* with the ERC721 standard. | ||
*/ | ||
function mintOneERC2309(address to) public { | ||
_mintERC2309(to, 1); | ||
} | ||
|
||
/** | ||
* @dev This function is only for gas comparison purposes. | ||
* Calling `_mintERC3201` outside of contract creation is non-compliant | ||
* with the ERC721 standard. | ||
*/ | ||
function mintTenERC2309(address to) public { | ||
_mintERC2309(to, 10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const { deployContract, offsettedIndex } = require('../helpers.js'); | ||
const { expect } = require('chai'); | ||
|
||
const createTestSuite = ({ contract, constructorArgs }) => | ||
function () { | ||
let offsetted; | ||
|
||
context(`${contract}`, function () { | ||
beforeEach(async function () { | ||
this.erc721aCounter = await deployContract(contract, constructorArgs); | ||
|
||
this.startTokenId = this.erc721aCounter.startTokenId | ||
? (await this.erc721aCounter.startTokenId()).toNumber() | ||
: 0; | ||
|
||
offsetted = (...arr) => offsettedIndex(this.startTokenId, arr); | ||
}); | ||
|
||
context('with minted tokens', async function () { | ||
beforeEach(async function () { | ||
const [owner, addr1] = await ethers.getSigners(); | ||
this.owner = owner; | ||
this.addr1 = addr1; | ||
|
||
this.addr1.expected = { | ||
balance: 1, | ||
tokens: [offsetted(0)], | ||
}; | ||
|
||
this.owner.expected = { | ||
balance: 2, | ||
tokens: offsetted(1, 2), | ||
}; | ||
|
||
this.mintOrder = [this.addr1, this.owner]; | ||
|
||
for (const minter of this.mintOrder) { | ||
const balance = minter.expected.balance; | ||
if (balance > 0) { | ||
await this.erc721aCounter['safeMint(address,uint256)'](minter.address, balance); | ||
} | ||
// sanity check | ||
expect(await this.erc721aCounter.balanceOf(minter.address)).to.equal(minter.expected.balance); | ||
} | ||
}); | ||
|
||
describe('_ownershipOf', function () { | ||
it('initial', async function () { | ||
for (const minter of this.mintOrder) { | ||
for (const tokenId in minter.expected.tokens) { | ||
const ownership = await this.erc721aCounter.getOwnershipOf(tokenId); | ||
expect(ownership.extraData).to.equal(42); | ||
} | ||
} | ||
}); | ||
|
||
it('after a transfer', async function () { | ||
await this.erc721aCounter.transferFrom(this.owner.address, this.addr1.address, 1); | ||
|
||
const tests = [ | ||
{ tokenId: 0, expectedData: 42 }, | ||
{ tokenId: 1, expectedData: 43 }, | ||
{ tokenId: 2, expectedData: 42 }, | ||
]; | ||
|
||
for (const test of tests) { | ||
const ownership = await this.erc721aCounter.getOwnershipOf(test.tokenId); | ||
expect(ownership.extraData).to.equal(test.expectedData); | ||
} | ||
}); | ||
|
||
it('after a burn', async function () { | ||
await this.erc721aCounter['burn(uint256)'](2); | ||
|
||
const tests = [ | ||
{ tokenId: 0, expectedData: 42 }, | ||
{ tokenId: 1, expectedData: 42 }, | ||
{ tokenId: 2, expectedData: 1337 }, | ||
]; | ||
|
||
for (const test of tests) { | ||
const ownership = await this.erc721aCounter.getOwnershipAt(test.tokenId); | ||
expect(ownership.extraData).to.equal(test.expectedData); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
describe( | ||
'ERC721A override _extraData()', | ||
createTestSuite({ | ||
contract: 'ERC721ATransferCounterMock', | ||
constructorArgs: ['Azuki', 'AZUKI'], | ||
}) | ||
); |