Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ’₯ Implement ERC-1155 Standard Token #31

Merged
merged 76 commits into from
Jan 15, 2023
Merged
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
689a9f3
πŸ“ EIP-1155 interfaces
pcaversaccio Dec 19, 2022
779a2d6
πŸ‘» basic EIP-1155 implementation
pcaversaccio Dec 19, 2022
ded156a
πŸ”— add reference links to EIPs in interfaces
pcaversaccio Dec 19, 2022
19deb3c
add contract & update interface
jtriley-eth Dec 21, 2022
c23fa29
add set_uri function
jtriley-eth Dec 21, 2022
cccfd22
add set minter function
jtriley-eth Dec 21, 2022
1a0bce6
add constructor stuffs
jtriley-eth Dec 21, 2022
12ddd56
add test boilerplate
jtriley-eth Dec 22, 2022
4d6577a
Merge branch 'main' into erc1155
pcaversaccio Dec 22, 2022
d2aa5a0
Merge branch 'main' into erc1155
pcaversaccio Dec 22, 2022
66d828a
Merge branch 'erc1155' into erc1155
jtriley-eth Dec 22, 2022
b778f46
Update src/tokens/interfaces/IERC1155Receiver.vy
jtriley-eth Dec 24, 2022
4a49f81
Update test/tokens/interfaces/IERC1155Extended.sol
jtriley-eth Dec 24, 2022
3100695
Update src/tokens/ERC1155.vy
jtriley-eth Dec 24, 2022
43a45a1
Update src/tokens/ERC1155.vy
jtriley-eth Dec 24, 2022
712b4de
Update src/tokens/ERC1155.vy
jtriley-eth Dec 24, 2022
c5996ae
Update test/tokens/interfaces/IERC1155Extended.sol
jtriley-eth Dec 24, 2022
dde010f
Update test/tokens/ERC1155.t.sol
jtriley-eth Dec 24, 2022
b9ff7da
Update src/tokens/ERC1155.vy
jtriley-eth Dec 24, 2022
ba47a3b
Apply suggestions from code review
jtriley-eth Dec 24, 2022
656c63e
add tests, mocks, minor edits to dynarray sizes
jtriley-eth Dec 24, 2022
391326c
add proper indent to natspec
jtriley-eth Dec 24, 2022
092abd4
update contract based on code review
jtriley-eth Dec 26, 2022
098d5b9
rm tests to decouple pr
jtriley-eth Dec 27, 2022
0c1b641
break out auth checks to external transfers and mints
jtriley-eth Dec 27, 2022
da61332
rm outdated todo
jtriley-eth Dec 27, 2022
d6fd1fc
πŸ”‚ Merge pull request #34 from jtriley-eth/erc1155
pcaversaccio Dec 28, 2022
1a7cddf
♻️ bump submodules
pcaversaccio Dec 28, 2022
1a8951b
πŸ“ docs: add note on return value bounds in interfaces
pcaversaccio Dec 28, 2022
ac9fc00
♻️formatting
pcaversaccio Dec 28, 2022
3f6d3db
πŸ”¨ add RoleMinterChanged event in erc20 & erc721 as well as improve docs
pcaversaccio Dec 28, 2022
89e21e2
πŸ”¨ first round of chore & refactor erc1155
pcaversaccio Dec 28, 2022
3e20a3e
πŸͺ› fixing missing hooks & event issuance in erc20 constructor
pcaversaccio Dec 28, 2022
c89dd59
♻️formatting
pcaversaccio Dec 28, 2022
92cccd8
πŸ”¨ second round of chore & refactor erc1155
pcaversaccio Dec 29, 2022
69ca5c0
πŸ”¨ core erc1155 logic should be ready
pcaversaccio Dec 29, 2022
a5f2ce1
πŸ”¨ we're getting there soon
pcaversaccio Dec 29, 2022
29c0dca
πŸ”₯ burnable functions
pcaversaccio Dec 29, 2022
2246b43
⚑️ minting
pcaversaccio Dec 29, 2022
71e6b19
Merge branch 'main' into erc1155
pcaversaccio Dec 30, 2022
738aeb1
♻️ bump submodules
pcaversaccio Dec 30, 2022
6d7aa78
Merge branch 'main' into erc1155
pcaversaccio Dec 30, 2022
bc98e9b
βš’ refactor \ o\ to \owner\ wording in internal mint functions of ERC721
pcaversaccio Dec 30, 2022
2592d6d
πŸ“ comments are important
pcaversaccio Dec 30, 2022
205accd
πŸ“ comments & safe consistency
pcaversaccio Dec 30, 2022
038eea8
Merge branch 'main' into erc1155
pcaversaccio Jan 1, 2023
632aced
Merge branch 'main' into erc1155
pcaversaccio Jan 2, 2023
fedd65f
♻️ cache base uri length
pcaversaccio Jan 2, 2023
a6a2031
Merge branch 'main' into erc1155
pcaversaccio Jan 3, 2023
f17430f
Merge branch 'main' into erc1155
pcaversaccio Jan 5, 2023
a0e7bee
♻️ change readme sequence
pcaversaccio Jan 5, 2023
f3e1743
Merge branch 'main' into erc1155
pcaversaccio Jan 8, 2023
c4befea
Merge branch 'main' into erc1155
pcaversaccio Jan 9, 2023
080754f
add tests, mocks
jtriley-eth Jan 10, 2023
1d03715
♻️ prettier and fix typo
pcaversaccio Jan 12, 2023
28099a0
♻️ change logic sequence in test interfaces
pcaversaccio Jan 12, 2023
3075e62
πŸ›  refactor receiver mock & ix broken link
pcaversaccio Jan 12, 2023
a980213
♻️ remove unused imports & refactor first part of test suite
pcaversaccio Jan 12, 2023
e9ec14a
♻️ add IERC165 to IERC1155Receiver interface and change visibility t…
pcaversaccio Jan 12, 2023
2ca5d34
♻️ add missing IERC165 functions to interfaces
pcaversaccio Jan 12, 2023
305b8ce
♻️ enhance balanceOf and balanceOfBatch tests
pcaversaccio Jan 12, 2023
d35f4bd
♻️ enhance setApprovalForAll tests
pcaversaccio Jan 12, 2023
ff33c77
πŸ›  small refactor
pcaversaccio Jan 12, 2023
03087ad
♻️ enhance safeTransferFrom tests
pcaversaccio Jan 12, 2023
5b6d41d
♻️ enhance ownership function tests
pcaversaccio Jan 13, 2023
7d0100f
πŸ”¨ refactor transfer_ownership and renounce_ownership functions
pcaversaccio Jan 13, 2023
66fc991
♻️ enhance safBatchTransferFrom tests
pcaversaccio Jan 13, 2023
e764ac6
♻️ enhance uri and set_uri functions
pcaversaccio Jan 13, 2023
34f5535
♻️ add total_supply and exists tests
pcaversaccio Jan 13, 2023
c181885
♻️ enhance burn tests
pcaversaccio Jan 13, 2023
f94a872
♻️ enhance set_minter tests
pcaversaccio Jan 13, 2023
f6b7820
♻️ enhance safe_mint and safe_mint_batch tests
pcaversaccio Jan 13, 2023
ecc0844
♻️ add gas snapshot
pcaversaccio Jan 13, 2023
f031a87
♻️ format constructor args
pcaversaccio Jan 15, 2023
19f2e88
πŸ”¨ refactor ERC1155 tests
pcaversaccio Jan 15, 2023
35381ff
♻️ gas snapshot
pcaversaccio Jan 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
♻️ enhance balanceOf and balanceOfBatch tests
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed Jan 12, 2023
commit 305b8ce4852c4f22ea09663b3d66c68d30c0a169
233 changes: 160 additions & 73 deletions test/tokens/ERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,166 @@ contract ERC1155Test is Test {
assertTrue(!ERC1155Extended.supportsInterface(0x0011bbff));
}

function testBalanceOfCase1() public {
address deployer = address(vyperDeployer);
address firstOwner = vm.addr(1);
address secondOwner = vm.addr(2);
bytes memory data = new bytes(0);
vm.startPrank(deployer);
ERC1155Extended.safe_mint(firstOwner, 0, 1, data);
ERC1155Extended.safe_mint(secondOwner, 1, 20, data);
assertEq(ERC1155Extended.balanceOf(firstOwner, 0), 1);
assertEq(ERC1155Extended.balanceOf(secondOwner, 1), 20);
assertEq(ERC1155Extended.balanceOf(firstOwner, 2), 0);
vm.stopPrank();
}

function testBalanceOfCase2() public {
assertEq(ERC1155Extended.balanceOf(vm.addr(1), 0), 0);
assertEq(ERC1155Extended.balanceOf(vm.addr(2), 1), 0);
assertEq(ERC1155Extended.balanceOf(vm.addr(3), 2), 0);
}

function testBalanceOfZeroAddress() public {
vm.expectRevert(bytes("ERC1155: address zero is not a valid owner"));
ERC1155Extended.balanceOf(address(0), 0);
}

function testBalanceOfBatchCase1() public {
address deployer = address(vyperDeployer);
address firstOwner = vm.addr(1);
address secondOwner = vm.addr(2);
address[] memory owners = new address[](6);
uint256[] memory ids = new uint256[](6);
uint256[] memory amounts = new uint256[](6);
bytes memory data = new bytes(0);

owners[0] = firstOwner;
owners[1] = firstOwner;
owners[2] = secondOwner;
owners[3] = secondOwner;
owners[4] = firstOwner;
owners[5] = secondOwner;
ids[0] = 0;
ids[1] = 1;
ids[2] = 2;
ids[3] = 3;
ids[4] = 4;
ids[5] = 5;
amounts[0] = 1;
amounts[1] = 2;
amounts[2] = 10;
amounts[3] = 20;
amounts[4] = 0;
amounts[5] = 0;

vm.startPrank(deployer);
ERC1155Extended.safe_mint(owners[0], ids[0], amounts[0], data);
ERC1155Extended.safe_mint(owners[1], ids[1], amounts[1], data);
ERC1155Extended.safe_mint(owners[2], ids[2], amounts[2], data);
ERC1155Extended.safe_mint(owners[3], ids[3], amounts[3], data);
uint256[] memory balances = ERC1155Extended.balanceOfBatch(owners, ids);
assertEq(balances.length, 6);
for (uint256 i; i < balances.length; ++i) {
assertEq(balances[i], amounts[i]);
}
vm.stopPrank();
}

function testBalanceOfBatchCase2() public {
address deployer = address(vyperDeployer);
address firstOwner = vm.addr(1);
address secondOwner = vm.addr(2);
address[] memory owners = new address[](6);
uint256[] memory ids = new uint256[](6);
uint256[] memory amounts = new uint256[](6);
bytes memory data = new bytes(0);

owners[0] = firstOwner;
owners[1] = firstOwner;
owners[2] = owners[0];
owners[3] = secondOwner;
owners[4] = firstOwner;
owners[5] = owners[3];
ids[0] = 0;
ids[1] = 1;
ids[2] = ids[0];
ids[3] = 3;
ids[4] = 4;
ids[5] = ids[3];
amounts[0] = 1;
amounts[1] = 2;
amounts[2] = amounts[0];
amounts[3] = 20;
amounts[4] = 0;
amounts[5] = amounts[3];

vm.startPrank(deployer);
ERC1155Extended.safe_mint(owners[0], ids[0], amounts[0] - 1, data);
ERC1155Extended.safe_mint(owners[1], ids[1], amounts[1], data);
ERC1155Extended.safe_mint(owners[2], ids[2], amounts[2], data);
ERC1155Extended.safe_mint(owners[3], ids[3], amounts[3], data);
uint256[] memory balances = ERC1155Extended.balanceOfBatch(owners, ids);
assertEq(balances.length, 6);
for (uint256 i; i < balances.length; ++i) {
assertEq(balances[i], amounts[i]);
}
vm.stopPrank();
}

function testBalanceOfBatchCase3() public {
address firstOwner = vm.addr(1);
address secondOwner = vm.addr(2);
address[] memory owners = new address[](6);
uint256[] memory ids = new uint256[](6);

owners[0] = firstOwner;
owners[1] = firstOwner;
owners[2] = secondOwner;
owners[3] = secondOwner;
owners[4] = firstOwner;
owners[5] = secondOwner;
ids[0] = 0;
ids[1] = 1;
ids[2] = 2;
ids[3] = 3;
ids[4] = 4;
ids[5] = 5;

uint256[] memory balances = ERC1155Extended.balanceOfBatch(owners, ids);
assertEq(balances.length, 6);
for (uint256 i; i < balances.length; ++i) {
assertEq(balances[i], 0);
}
}

function testBalanceOfBatchLengthsMismatch() public {
address[] memory owners1 = new address[](2);
uint256[] memory ids1 = new uint256[](1);
owners1[0] = vm.addr(1);
owners1[1] = vm.addr(2);
ids1[0] = 0;
vm.expectRevert(bytes("ERC1155: owners and ids length mismatch"));
ERC1155Extended.balanceOfBatch(owners1, ids1);

address[] memory owners2 = new address[](1);
uint256[] memory ids2 = new uint256[](2);
owners2[0] = vm.addr(3);
ids2[0] = 0;
ids2[1] = 1;
vm.expectRevert(bytes("ERC1155: owners and ids length mismatch"));
ERC1155Extended.balanceOfBatch(owners2, ids2);
}

function testBalanceOfBatchZeroAddress() public {
address[] memory owners = new address[](1);
uint256[] memory ids = new uint256[](1);
owners[0] = address(0);
ids[0] = 0;
vm.expectRevert(bytes("ERC1155: address zero is not a valid owner"));
ERC1155Extended.balanceOfBatch(owners, ids);
}

// function testSafeTransferFromReceiverNotAContract() public {
// //transfer to EOA
// address deployer = address(vyperDeployer);
Expand Down Expand Up @@ -510,79 +670,6 @@ contract ERC1155Test is Test {
// erc1155.safeBatchTransferFrom(owner, receiver, ids, amounts, data);
// }

// function testBalanceOf() public {
// //balance read
// address deployer = address(vyperDeployer);
// address owner = vm.addr(1);
// bytes memory data = new bytes(0);

// vm.prank(deployer);
// erc1155.safe_mint(owner, 0, 1, data);

// assertEq(erc1155.balanceOf(owner, 0), 1);
// assertEq(erc1155.balanceOf(owner, 1), 0);
// }

// function testBalanceOfAddressZero() public {
// //balance read zero address
// vm.expectRevert(bytes("ERC1155: address zero is not a valid owner"));

// erc1155.balanceOf(address(0), 0);
// }

// function testBalanceOfBatch() public {
// //batch balance read
// address deployer = address(vyperDeployer);
// address[] memory owners = new address[](2);
// uint256[] memory ids = new uint256[](2);
// uint256[] memory amounts = new uint256[](2);
// bytes memory data = new bytes(0);

// owners[0] = vm.addr(1);
// owners[1] = vm.addr(1);
// ids[0] = 0;
// ids[1] = 1;
// amounts[0] = 1;
// amounts[1] = 2;

// vm.prank(deployer);
// erc1155.safe_mint_batch(owners[0], ids, amounts, data);

// uint256[] memory balances = erc1155.balanceOfBatch(owners, ids);

// assertEq(balances.length, 2);

// for (uint256 i; i < balances.length; ++i) {
// assertEq(balances[i], amounts[i]);
// }
// }

// function testBalanceOfBatchBatchLengthsMismatch() public {
// //batch balance read owners and ids lengths mismatch
// address[] memory owners = new address[](2);
// uint256[] memory ids = new uint256[](1);

// owners[0] = vm.addr(1);
// owners[1] = vm.addr(2);
// ids[0] = 0;

// vm.expectRevert(bytes("ERC1155: owners and ids length mismatch"));
// erc1155.balanceOfBatch(owners, ids);
// }

// function testBalanceOfBatchZeroAddress() public {
// //batch balance read owners includes zero address
// address[] memory owners = new address[](1);
// uint256[] memory ids = new uint256[](1);

// owners[0] = address(0);
// ids[0] = 0;

// vm.expectRevert(bytes("ERC1155: address zero is not a valid owner"));

// erc1155.balanceOfBatch(owners, ids);
// }

// function testSetApprovalForAll() public {
// //set operator status
// address account = vm.addr(1);
Expand Down