Fix multiple mint batch overflow capacity

pull/64/head
kompotkot 2022-11-17 13:44:28 +00:00
rodzic 67a8e7953a
commit 6a33ade9df
3 zmienionych plików z 39 dodań i 4 usunięć

Wyświetl plik

@ -1,4 +1,5 @@
# dao # dao
Moonstream DAO Moonstream DAO
## Decentralizing Moonstream ## Decentralizing Moonstream
@ -10,11 +11,12 @@ We run our own blockchain nodes (currently Ethereum and Polygon), and perform al
through these nodes. through these nodes.
The coming years will bring an explosion of decentralized applications with a presence on multiple The coming years will bring an explosion of decentralized applications with a presence on multiple
blockchains. We aim to bring the value of Moonstream to *every* major blockchain, and to do so in a blockchains. We aim to bring the value of Moonstream to _every_ major blockchain, and to do so in a
truly decentralized manner. No other approach will scale to tens and eventually hundreds of supported truly decentralized manner. No other approach will scale to tens and eventually hundreds of supported
blockchains. blockchains.
Moonstream DAO represents this decentralization. The DAO will reward participants who contribute: Moonstream DAO represents this decentralization. The DAO will reward participants who contribute:
1. Blockchain node time 1. Blockchain node time
2. Crawler time 2. Crawler time
3. Crawler code 3. Crawler code
@ -111,19 +113,27 @@ moonworm generate-brownie -p . -o dao -n TerminusFacet
### Tests ### Tests
Make sure you have `ganache-cli`:
```
npm install -g ganache-cli
```
To run unit tests, run: `./test.sh` To run unit tests, run: `./test.sh`
Before you do this, you must make sure that a Python environment is available in your shell and that Before you do this, you must make sure that a Python environment is available in your shell and that
you have installed the development dependencies in this environment. you have installed the development dependencies in this environment.
For specific test case use commands like: `./test.sh dao.test_terminus.TestPoolOperations`
### VSCode setup ### VSCode setup
If you are using the Solidity extension in VSCode, merge the following snippet into your settings.json: If you are using the Solidity extension in VSCode, merge the following snippet into your settings.json:
```json ```json
{ {
"solidity.remappings": [ "solidity.remappings": [
"@openzeppelin-contracts/=<path to your home directory>/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.3.2" "@openzeppelin-contracts/=<path to your home directory>/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.3.2"
] ]
} }
``` ```

Wyświetl plik

@ -386,11 +386,19 @@ contract ERC1155WithTerminusStorage is
LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage(); LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage();
uint256[] memory uniqueIds = new uint256[](ids.length);
for (uint256 i = 0; i < ids.length; i++) { for (uint256 i = 0; i < ids.length; i++) {
require( require(
ts.poolSupply[ids[i]] + amounts[i] <= ts.poolCapacity[ids[i]], ts.poolSupply[ids[i]] + amounts[i] <= ts.poolCapacity[ids[i]],
"ERC1155WithTerminusStorage: _mintBatch -- Minted tokens would exceed pool capacity" "ERC1155WithTerminusStorage: _mintBatch -- Minted tokens would exceed pool capacity"
); );
for (uint256 j = 0; j < uniqueIds.length; j++) {
require(
ids[i] != uniqueIds[j],
"ERC1155WithTerminusStorage: _mintBatch -- Only unique pool ids are allowed"
);
}
uniqueIds[i] = ids[i];
} }
address operator = _msgSender(); address operator = _msgSender();

Wyświetl plik

@ -349,6 +349,23 @@ class TestPoolOperations(TerminusTestCase):
supply = self.diamond_terminus.terminus_pool_supply(pool_id) supply = self.diamond_terminus.terminus_pool_supply(pool_id)
self.assertEqual(supply, 0) self.assertEqual(supply, 0)
def test_mint_batch_fails_if_it_exceeds_capacity_not_unique(self):
pool_id = self.diamond_terminus.total_pools()
with self.assertRaises(Exception):
self.diamond_terminus.mint_batch(
accounts[2].address,
pool_i_ds=[pool_id for _ in range(0, 11)],
amounts=[1 for _ in range(0, 11)],
data=b"",
transaction_config={"from": accounts[1]},
)
balance = self.diamond_terminus.balance_of(accounts[2].address, pool_id)
self.assertEqual(balance, 0)
supply = self.diamond_terminus.terminus_pool_supply(pool_id)
self.assertEqual(supply, 0)
def test_pool_mint_batch(self): def test_pool_mint_batch(self):
pool_id = self.diamond_terminus.total_pools() pool_id = self.diamond_terminus.total_pools()
target_accounts = [account.address for account in accounts[:5]] target_accounts = [account.address for account in accounts[:5]]