Skip to content

Commit

Permalink
🎨 improve
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkac committed Dec 20, 2024
1 parent f291543 commit e62118f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
14 changes: 5 additions & 9 deletions src/components/vintage/vintage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub mod VintageComponent {
pub mod Errors {
pub const INVALID_ARRAY_LENGTH: felt252 = 'Vintage: invalid array length';
pub const INVALID_STARTING_YEAR: felt252 = 'Vintage: invalid starting year';
pub const INVALID_CALLER: felt252 = 'Vintage: invalid caller';
}

#[embeddable_as(VintageImpl)]
Expand Down Expand Up @@ -216,21 +217,16 @@ pub mod VintageComponent {
let supply = *yearly_absorptions.at(index);
let token_id = (index + 1).into();
let old_vintage = self.Vintage_vintages.entry(token_id).read();
let mut vintage = CarbonVintage {
let new_vintage = CarbonVintage {
year: (start_year + index).into(),
supply: supply,
failed: 0,
created: 0,
status: CarbonVintageType::Projected,
};
self.Vintage_vintages.entry(token_id).write(vintage);
self.Vintage_vintages.entry(token_id).write(new_vintage);

self
.emit(
VintageUpdate {
token_id: index.into(), old_vintage: old_vintage, new_vintage: vintage
}
);
self.emit(VintageUpdate { token_id, old_vintage, new_vintage });
index += 1;
};
}
Expand Down Expand Up @@ -273,7 +269,7 @@ pub mod VintageComponent {
// [Check] Caller has role
let caller = get_caller_address();
let has_role = self.get_contract().has_role(role, caller);
assert(has_role, 'Caller does not have role');
assert(has_role, Errors::INVALID_CALLER);
}
}
}
13 changes: 0 additions & 13 deletions tests/test_mint.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,6 @@ fn test_public_buy() {
minter.public_buy(cc_to_buy);

let token_ids = helper_get_token_ids(project_address);
// TODO: helper for amounts here?

// let mut cc_amounts: Array<u256> = Default::default();
// let mut index = 0;
// loop {
// if index >= token_ids.len() {
// break ();
// }
// let token_id = *token_ids.at(index);
// let cc_value = project_contract.internal_to_cc(cc_to_buy, token_id);
// cc_amounts.append(cc_value);
// index += 1;
// };

let expected_events = helper_expected_transfer_single_events(
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vintage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn test_set_vintages() {
}

#[test]
#[should_panic(expected: 'Caller does not have role')]
#[should_panic(expected: 'Vintage: invalid caller')]
fn test_set_vintages_without_owner_role() {
let project_address = deploy_project();
let yearly_absorptions = get_mock_absorptions();
Expand Down Expand Up @@ -225,7 +225,7 @@ fn test_update_vintage_status_invalid() {
}

#[test]
#[should_panic(expected: 'Caller does not have role')]
#[should_panic(expected: 'Vintage: invalid caller')]
fn test_update_vintage_status_without_owner_role() {
let project_address = deploy_project();
let user_address: ContractAddress = contract_address_const::<'USER'>();
Expand Down

0 comments on commit e62118f

Please sign in to comment.