diff --git a/src/components/vintage/vintage.cairo b/src/components/vintage/vintage.cairo index 40b0591..f6f06e8 100644 --- a/src/components/vintage/vintage.cairo +++ b/src/components/vintage/vintage.cairo @@ -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)] @@ -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; }; } @@ -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); } } } diff --git a/tests/test_mint.cairo b/tests/test_mint.cairo index 881f073..580ac5e 100644 --- a/tests/test_mint.cairo +++ b/tests/test_mint.cairo @@ -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 = 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 diff --git a/tests/test_vintage.cairo b/tests/test_vintage.cairo index 64b0286..6faa95e 100644 --- a/tests/test_vintage.cairo +++ b/tests/test_vintage.cairo @@ -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(); @@ -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'>();