Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanhan101 committed Sep 1, 2023
1 parent 833d429 commit 3643384
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ tmp.*

/target

account
accounts
keys
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
# LeetLoot

## Deploy with Starkli


Initialize a signer and account if haven't. Otherwise check its correctness
```
starkli signer keystore new keys/key.json
export STARKNET_KEYSTORE="/workspaces/leetloot/keys/key.json"
```

```
starkli account oz init accounts/account.json
export STARKNET_ACCOUNT="/workspaces/leetloot/accounts/account.json"
```

Deploy the account if haven't
```
starkli account deploy accounts/account.json
```

Test and build the contract
```
scarb test && scarb build
```

Declare contract
```
starkli declare --account accounts/account.json --rpc <RPC_URL> --network goerli-1 ./target/dev/LootSurvivorBeasts_Beasts.sierra.json
```

Helpful Cairo string conversion
```
starkli to-cairo-string BEASTS
```

Deploy contract with argument resolution
```
starkli deploy --account accounts/account.json --rpc <RPC_URL> <CLASS_HASH> <OWNER_ADDRESS> <WHITELIST_ADDRESS> str:Beasts str:BEASTS
```

Get transaction
```
starkli transaction --rpc <RPC_URL> <TRANSACTION_HASH>
```

## Deploy

If you have a deployer account, double check its correctness
Expand Down
5 changes: 2 additions & 3 deletions src/beasts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ mod Beasts {
}

fn _assertOnlyOwner(self: @ContractState) {
let owner: ContractAddress = self._owner.read();
let caller: ContractAddress = get_caller_address();
//assert(!caller.is_zero(), 'Zero address');
//assert(caller == owner, 'Not owner');
assert(!caller.is_zero(), 'Zero address');
assert(caller == self.owner(), 'Not owner');
}

fn _transferOwnership(ref self: ContractState, to: ContractAddress) {
Expand Down
50 changes: 19 additions & 31 deletions src/tests/deploy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ mod tests {
use result::ResultTrait;
use LootSurvivorBeasts::beasts::{LongString, Beasts};
use LootSurvivorBeasts::interfaces::{IBeastsDispatcher, IBeastsDispatcherTrait};
use starknet::testing::{set_caller_address};
use starknet::testing::{set_caller_address, set_contract_address};

fn DAO() -> ContractAddress {
contract_address_const::<0x168893664220f03a74a9bce84228b009df46040c08bb308783dcf130790335f>()
}

fn deploy() -> IBeastsDispatcher {
set_caller_address(DAO());
set_contract_address(DAO());

let calldata = array![DAO().into(), DAO().into(), 'Beasts', 'Beasts'];

Expand All @@ -33,6 +34,7 @@ mod tests {
let contract = deploy();
let owner = contract.owner();

assert(DAO().into() == owner, 'Wrong owner');
assert(contract.name() == 'Beasts', 'Wrong name');
assert(contract.symbol() == 'Beasts', 'Wrong symbol');
assert(contract.tokenSupply() == 0, 'Wrong supply');
Expand All @@ -44,39 +46,25 @@ mod tests {
let contract = deploy();
let owner = contract.owner();

assert(DAO().into() == owner, 'Wrong owner');
set_caller_address(DAO());
contract.mintGenesis(owner);

assert(starknet::get_caller_address() == owner, 'Wrong caller');
assert(contract.tokenSupply() == 75, 'Wrong supply');
}
}
// assert(contract.supportsInterface(0x80ac58cd), 'No support interface');
// assert(!contract.supportsInterface(0x150b7a02), 'No support interface');
// contract.registerInterface(0x150b7a02);
// assert(contract.supportsInterface(0x150b7a02), 'No support interface');
// // Comment out because there's no good way to mock caller address yet
// // Also, felt252 13104 is string 30
// assert(!contract.isMinted(1, 1, 1), 'Already minted');
// contract.mint(owner, 1, 1, 1, 13104);
// // contract.mint(owner, 1, 1, 1, 13104); // should panic here
// assert(contract.isMinted(1, 1, 1), 'Already minted');
// assert(contract.isMinted(1, 1, 1), 'Already minted');
// assert(contract.tokenSupply() == 1, 'Wrong supply');
// let uri = contract.tokenURI(0);
// let mut i = 0_usize;
// loop {
// if i == uri.len() {
// break;
// }

// (*uri[i]).print();
// i += 1;
// };

// assert(!contract.isMinted(2, 2, 2), 'Already minted');
// contract.mint(owner, 2, 2, 2, 13104);
// assert(contract.tokenSupply() == 2, 'Wrong supply');

#[test]
#[available_gas(3000000)]
fn test_mint() {
let contract = deploy();
let owner = contract.owner();

assert(contract.supportsInterface(0x80ac58cd), 'No support interface');
assert(!contract.supportsInterface(0x150b7a02), 'No support interface');
contract.registerInterface(0x150b7a02);
assert(contract.supportsInterface(0x150b7a02), 'No support interface');
assert(!contract.isMinted(1, 1, 1), 'Already minted');
assert(!contract.isMinted(1, 1, 1), 'Not minted');
contract.mint(owner, 1, 1, 1, 13104);
assert(contract.isMinted(1, 1, 1), 'Already minted');
assert(contract.tokenSupply() == 1, 'Wrong supply');
}
}

0 comments on commit 3643384

Please sign in to comment.