-
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.
Add a generic interface for ownership storage hitchhiking (#323)
* Add a generic interface for ownership storage hitchhiking * Add own 24bit extra data field * Clean up test and remove a rogue only * Update IERC721AQueryable.sol * Update ERC721ATransferCounterMock.sol * Update IERC721A.sol * Update IERC721AQueryable.sol * Update ERC721A.sol * Update ERC721AQueryable.sol * Add requested changes Co-authored-by: Vectorized <webby1111@hotmail.com>
- Loading branch information
1 parent
ad0722c
commit c7248cc
Showing
7 changed files
with
202 additions
and
25 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
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
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'], | ||
}) | ||
); |