Skip to content

Commit

Permalink
use the array macro
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jan 17, 2024
1 parent f2c89f2 commit 1322886
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/airdrop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Claim {
#[starknet::interface]
trait IAirdrop<TStorage> {
// Claims the given allotment of tokens
fn claim(ref self: TStorage, claim: Claim, proof: Array::<felt252>);
fn claim(ref self: TStorage, claim: Claim, proof: Array<felt252>);

// Return the root of the airdrop
fn get_root(self: @TStorage) -> felt252;
Expand Down
33 changes: 8 additions & 25 deletions src/airdrop_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ fn deploy(token: ContractAddress, root: felt252) -> IAirdropDispatcher {
#[test]
#[available_gas(3000000)]
fn test_compute_pedersen_root_example_lt() {
let mut arr = ArrayTrait::new();
arr.append(1235);
assert(
compute_pedersen_root(
1234, arr.span()
1234, array![1235].span()
) == 0x24e78083d17aa2e76897f44cfdad51a09276dd00a3468adc7e635d76d432a3b,
'example'
);
Expand All @@ -46,11 +44,9 @@ fn test_compute_pedersen_root_example_lt() {
#[test]
#[available_gas(3000000)]
fn test_compute_pedersen_root_example_gt() {
let mut arr = ArrayTrait::new();
arr.append(1233);
assert(
compute_pedersen_root(
1234, arr.span()
1234, array![1233].span()
) == 0x2488766c14e4bfd8299750797eeb07b7045398df03ea13cf33f0c0c6645d5f9,
'example'
);
Expand All @@ -59,11 +55,9 @@ fn test_compute_pedersen_root_example_gt() {
#[test]
#[available_gas(3000000)]
fn test_compute_pedersen_root_example_eq() {
let mut arr = ArrayTrait::new();
arr.append(1234);
assert(
compute_pedersen_root(
1234, arr.span()
1234, array![1234].span()
) == 0x7a7148565b76ae90576733160aa3194a41ce528ee1434a64a9da50dcbf6d3ca,
'example'
);
Expand All @@ -72,19 +66,15 @@ fn test_compute_pedersen_root_example_eq() {
#[test]
#[available_gas(3000000)]
fn test_compute_pedersen_root_empty() {
let mut arr = ArrayTrait::new();
assert(compute_pedersen_root(1234, arr.span()) == 1234, 'example');
assert(compute_pedersen_root(1234, array![].span()) == 1234, 'example');
}

#[test]
#[available_gas(3000000)]
fn test_compute_pedersen_root_recursive() {
let mut arr = ArrayTrait::new();
arr.append(1234);
arr.append(1234);
assert(
compute_pedersen_root(
1234, arr.span()
1234, array![1234, 1234].span()
) == 0xc92a4f7aa8979b0202770b378e46de07bebe0836f8ceece5a47ccf3929c6b0,
'example'
);
Expand Down Expand Up @@ -151,10 +141,7 @@ fn test_invalid_proof_single_entry() {
let airdrop = deploy(token.contract_address, leaf);

token.transfer(airdrop.contract_address, 6789);
let mut proof = ArrayTrait::new();
proof.append(1);

airdrop.claim(claim, proof);
airdrop.claim(claim, array![1]);
}

#[test]
Expand Down Expand Up @@ -196,15 +183,11 @@ fn test_claim_two_claims() {
let airdrop = deploy(token.contract_address, root);
token.transfer(airdrop.contract_address, 6789 + 789 + 1);

let mut proof_a = ArrayTrait::new();
proof_a.append(leaf_b);
airdrop.claim(claim_a, proof_a);
airdrop.claim(claim_a, array![leaf_b]);
assert(token.balance_of(airdrop.contract_address) == (789 + 1), 'claim a taken');
assert(token.balance_of(claim_a.claimee) == 6789, 'received');

let mut proof_b = ArrayTrait::new();
proof_b.append(leaf_a);
airdrop.claim(claim_b, proof_b);
airdrop.claim(claim_b, array![leaf_a]);
assert(token.balance_of(airdrop.contract_address) == 1, 'claim b taken');
assert(token.balance_of(claim_b.claimee) == 789, 'received');
}
9 changes: 2 additions & 7 deletions src/call_trait_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ fn test_hash_address_entry_point_one() {
#[test]
#[available_gas(300000000)]
fn test_hash_address_data_one() {
let mut calldata: Array<felt252> = ArrayTrait::new();
calldata.append(1);
let call = Call { to: contract_address_const::<0>(), selector: 0, calldata: calldata };
let call = Call { to: contract_address_const::<0>(), selector: 0, calldata: array![1] };

assert(
LegacyHash::hash(
Expand All @@ -59,10 +57,7 @@ fn test_hash_address_data_one() {
#[test]
#[available_gas(300000000)]
fn test_hash_address_data_one_two() {
let mut calldata: Array<felt252> = ArrayTrait::new();
calldata.append(1);
calldata.append(2);
let call = Call { to: contract_address_const::<0>(), selector: 0, calldata: calldata };
let call = Call { to: contract_address_const::<0>(), selector: 0, calldata: array![1, 2] };

assert(
LegacyHash::hash(
Expand Down
4 changes: 1 addition & 3 deletions src/timelock_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ fn transfer_call(
}

fn single_call(call: Call) -> Span<Call> {
let mut calls: Array<Call> = ArrayTrait::new();
calls.append(call);
return calls.span();
return array![call].span();
}

#[test]
Expand Down

0 comments on commit 1322886

Please sign in to comment.