From 0ade782f4e0275061d2942765f048cda2e5e38dc Mon Sep 17 00:00:00 2001 From: loothero Date: Thu, 26 Oct 2023 14:51:30 +0000 Subject: [PATCH] closes #6: prevent double genesis mint --- src/beasts.cairo | 8 ++++++-- src/tests/deploy.cairo | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/beasts.cairo b/src/beasts.cairo index 851f01c..178b1fb 100644 --- a/src/beasts.cairo +++ b/src/beasts.cairo @@ -48,7 +48,8 @@ mod Beasts { _tokenIndex: u256, _supportedInterfaces: LegacyMap, _minted: LegacyMap::, - _beast: LegacyMap + _beast: LegacyMap, + _genesis_mint: bool, } #[event] @@ -321,6 +322,7 @@ mod Beasts { fn mintGenesisBeasts(ref self: ContractState, to: ContractAddress) { self._assertOnlyOwner(); + assert(self._genesis_mint.read() == false, 'Already minted'); let mut id = 1; loop { @@ -335,7 +337,9 @@ mod Beasts { self._mint(to); id += 1; - } + }; + + self._genesis_mint.write(true); } } } diff --git a/src/tests/deploy.cairo b/src/tests/deploy.cairo index 9a58adc..60e1b50 100644 --- a/src/tests/deploy.cairo +++ b/src/tests/deploy.cairo @@ -51,6 +51,16 @@ mod tests { assert(contract.tokenSupply() == 75, 'Wrong supply'); } + #[test] + #[should_panic(expected: ('Already minted', 'ENTRYPOINT_FAILED'))] + #[available_gas(136114530)] + fn test_mint_genesis_twice() { + let contract = deploy(); + let owner = contract.owner(); + contract.mintGenesisBeasts(owner); + contract.mintGenesisBeasts(owner); + } + #[test] #[available_gas(3000000)] fn test_mint() {