Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions contract_/src/audition/interfaces/iseason_and_audition.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use contract_::audition::types::season_and_audition::{
Appeal, ArtistRegistration, Audition, Evaluation, Genre, RegistrationConfig, Season, Vote,
Appeal, Audition, Evaluation, Genre, RegistrationConfig, Season, Vote,
};
use starknet::ContractAddress;

Expand Down Expand Up @@ -59,26 +59,19 @@ pub trait ISeasonAndAudition<TContractState> {
ref self: TContractState, audition_id: u256, token_address: ContractAddress, amount: u256,
);

fn distribute_prize(
ref self: TContractState,
audition_id: u256,
winners: [ContractAddress; 3],
shares: [u256; 3],
);
fn distribute_prize(ref self: TContractState, audition_id: u256, shares: Array<u256>);

fn get_audition_prices(self: @TContractState, audition_id: u256) -> (ContractAddress, u256);

/// @notice Returns the winner addresses for a given audition.
/// @param audition_id The unique identifier of the audition.
/// @return (ContractAddress, ContractAddress, ContractAddress) Tuple of winner addresses.
fn get_audition_winner_addresses(
self: @TContractState, audition_id: u256,
) -> (ContractAddress, ContractAddress, ContractAddress);
) -> Array<ContractAddress>;

/// @notice Returns the winner prize amounts for a given audition.
/// @param audition_id The unique identifier of the audition.
/// @return (u256, u256, u256) Tuple of winner prize amounts.
fn get_audition_winner_amounts(self: @TContractState, audition_id: u256) -> (u256, u256, u256);
fn get_audition_winner_amounts(self: @TContractState, audition_id: u256) -> Array<u256>;

/// @notice Returns whether the prize has been distributed for a given audition.
/// @param audition_id The unique identifier of the audition.
Expand Down
235 changes: 159 additions & 76 deletions contract_/src/audition/season_and_audition.cairo

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion contract_/src/audition/stake_to_vote.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub mod StakeToVote {
ISeasonAndAuditionDispatcher, ISeasonAndAuditionDispatcherTrait,
};
use contract_::audition::interfaces::istake_to_vote::IStakeToVote;
use contract_::audition::types::season_and_audition::Audition;
use contract_::audition::types::stake_to_vote::*;
use contract_::errors::errors;
use core::num::traits::Zero;
Expand Down
1 change: 0 additions & 1 deletion contract_/src/audition/stake_withdrawal.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub mod StakeWithdrawal {
use contract_::audition::interfaces::istake_to_vote::{
IStakeToVoteDispatcher, IStakeToVoteDispatcherTrait,
};
use contract_::audition::types::season_and_audition::Audition;
use contract_::audition::types::stake_to_vote::{StakerInfo, StakingConfig};
use core::num::traits::Zero;
use openzeppelin::access::ownable::OwnableComponent;
Expand Down
4 changes: 2 additions & 2 deletions contract_/src/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub struct VoteRecorded {
#[derive(Drop, starknet::Event)]
pub struct PriceDistributed {
pub audition_id: u256,
pub winners: [ContractAddress; 3],
pub shares: [u256; 3],
pub winners: Span<ContractAddress>,
pub shares: Span<u256>,
pub token_address: ContractAddress,
pub amounts: Span<u256>,
}
Expand Down
10 changes: 5 additions & 5 deletions contract_/src/governance/ProposalSystem.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ pub mod ProposalSystem {
Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess,
StoragePointerWriteAccess,
};
use starknet::{
ContractAddress, contract_address_const, get_block_timestamp, get_caller_address,
};
use starknet::{ContractAddress, get_block_timestamp, get_caller_address};
use super::*;

const zero_address: ContractAddress = 0.try_into().unwrap();

#[storage]
struct Storage {
proposals: Map<u64, Proposal>,
Expand Down Expand Up @@ -237,7 +237,7 @@ pub mod ProposalSystem {
let proposal = self.proposals.read(current_id);

// Apply filters
let matches_token = token_contract == contract_address_const::<0>()
let matches_token = token_contract == zero_address
|| proposal.token_contract == token_contract;
let matches_status = status == 255_u8 || proposal.status == status;
let matches_category = category == 'ALL' || proposal.category == category;
Expand Down Expand Up @@ -475,7 +475,7 @@ pub mod ProposalSystem {
let current_artist = self.artists.read(token_contract);

// If no registered artist, register artist linked to token in factory contract
if current_artist == contract_address_const::<0>() {
if current_artist == zero_address {
let factory_dispatcher = IMusicShareTokenFactoryDispatcher {
contract_address: self.factory_contract.read(),
};
Expand Down
20 changes: 10 additions & 10 deletions contract_/src/governance/VotingMechanism.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ pub mod VotingMechanism {
Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess,
StoragePointerWriteAccess,
};
use starknet::{contract_address_const, get_block_timestamp, get_caller_address};
use starknet::{get_block_timestamp, get_caller_address};
use super::*;

const zero_address: ContractAddress = 0.try_into().unwrap();


#[storage]
struct Storage {
// Votes: (proposal_id, voter) -> Vote
Expand Down Expand Up @@ -128,7 +131,7 @@ pub mod VotingMechanism {
assert(!self.completed_votings.read(proposal_id), 'Voting has already ended');

// Check if user has already voted
assert(self.has_voted(proposal_id, caller) == false, 'Already voted');
assert(!self.has_voted(proposal_id, caller), 'Already voted');

// Ensure the vote type is valid
assert(vote_type != VoteType::None, 'Invalid vote type');
Expand All @@ -140,8 +143,7 @@ pub mod VotingMechanism {
}
// Check if the user has delegated their vote
let delegation = self.delegations.read(caller);
if delegation != contract_address_const::<0>()
&& self.delegation_weights.read(delegation) > 0 {
if delegation != zero_address && self.delegation_weights.read(delegation) > 0 {
// If caller already delegated, revert the vote
assert(self.has_voted(proposal_id, caller), 'Cannot vote after delegation');
}
Expand Down Expand Up @@ -226,9 +228,7 @@ pub mod VotingMechanism {
) {
let caller = get_caller_address();
assert(caller != delegate, 'Cannot delegate to self');
assert(
self.delegations.read(caller) == contract_address_const::<0>(), 'Already delegated',
);
assert(self.delegations.read(caller) == zero_address, 'Already delegated');

// Ensure delegator has token balance
let token = IERC20Dispatcher { contract_address: token_address };
Expand Down Expand Up @@ -290,7 +290,7 @@ pub mod VotingMechanism {
ref self: ContractState, proposal_id: u64, token_contract: ContractAddress,
) -> u8 {
assert(self._verify_proposal_id(proposal_id), 'Invalid proposal ID');
assert(self.is_voting_active(proposal_id) == false, 'Voting period is still active');
assert(!self.is_voting_active(proposal_id), 'Voting period is still active');

let proposal_system_dispatcher = IProposalSystemDispatcher {
contract_address: self.proposal_system.read(),
Expand Down Expand Up @@ -387,13 +387,13 @@ pub mod VotingMechanism {
let delegation_from_sender = self.delegations.read(from);
let delegation_to_receiver = self.delegations.read(to);

if delegation_from_sender != contract_address_const::<0>() {
if delegation_from_sender != zero_address {
// Sender has delegated - update delegate's effective voting power
self._update_delegated_weight(proposal_id, delegation_from_sender, amount, false);
delegation_affected = true;
}

if delegation_to_receiver != contract_address_const::<0>() {
if delegation_to_receiver != zero_address {
// Receiver has delegated - update delegate's effective voting power
self._update_delegated_weight(proposal_id, delegation_to_receiver, amount, true);
delegation_affected = true;
Expand Down
25 changes: 4 additions & 21 deletions contract_/tests/test_access_control_emergency_stop.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use contract_::audition::interfaces::iseason_and_audition::{
ISeasonAndAuditionDispatcher, ISeasonAndAuditionDispatcherTrait,
ISeasonAndAuditionSafeDispatcherTrait,
};
use contract_::audition::interfaces::iseason_and_audition::ISeasonAndAuditionDispatcherTrait;
use contract_::audition::season_and_audition::SeasonAndAudition;
use contract_::audition::types::season_and_audition::{Audition, Genre, Season};
use contract_::audition::types::season_and_audition::Genre;
use contract_::events::{PausedAll, ResumedAll};
use core::result::ResultTrait;
use snforge_std::{
ContractClassTrait, DeclareResultTrait, EventSpyAssertionsTrait, declare, spy_events,
start_cheat_caller_address, stop_cheat_caller_address,
EventSpyAssertionsTrait, spy_events, start_cheat_caller_address, stop_cheat_caller_address,
};
use starknet::{ContractAddress, get_block_timestamp};
use starknet::get_block_timestamp;
use crate::test_utils::*;

#[test]
Expand All @@ -21,12 +16,9 @@ fn test_owner_access_control() {
start_cheat_caller_address(dispatcher.contract_address, OWNER());

// Owner can create a season
let season_id = 1;
default_contract_create_season(dispatcher);

// Owner can create an audition
let audition_id = 1;
let test_audition = create_default_audition(audition_id, season_id);
dispatcher.create_audition('Summer Hits', Genre::Pop, 1675123200);

// Owner can add oracles
Expand All @@ -43,7 +35,6 @@ fn test_non_owner_cannot_create_season() {
// Non-owner tries to create a season
start_cheat_caller_address(dispatcher.contract_address, USER());

let season_id = 1;
default_contract_create_season(dispatcher);

stop_cheat_caller_address(dispatcher.contract_address);
Expand All @@ -57,9 +48,6 @@ fn test_non_owner_cannot_create_audition() {
// Non-owner tries to create an audition
start_cheat_caller_address(dispatcher.contract_address, USER());

let audition_id = 1;
let season_id = 1;
let test_audition = create_default_audition(audition_id, season_id);
dispatcher.create_audition('Summer Hits', Genre::Pop, 1675123200);

stop_cheat_caller_address(dispatcher.contract_address);
Expand Down Expand Up @@ -173,7 +161,6 @@ fn test_cannot_create_season_when_paused() {
dispatcher.pause_all();

// Try to create a season when paused
let season_id = 1;
default_contract_create_season(dispatcher);

stop_cheat_caller_address(dispatcher.contract_address);
Expand All @@ -188,10 +175,6 @@ fn test_cannot_create_audition_when_paused() {
start_cheat_caller_address(dispatcher.contract_address, OWNER());
dispatcher.pause_all();

// Try to create an audition when paused
let audition_id = 1;
let season_id = 1;
let test_audition = create_default_audition(audition_id, season_id);
dispatcher.create_audition('Summer Hits', Genre::Pop, 1675123200);

stop_cheat_caller_address(dispatcher.contract_address);
Expand Down
2 changes: 1 addition & 1 deletion contract_/tests/test_audition_registration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn test_audition_registration_config_update_flow() {
}

#[test]
#[should_panic(expected: 'Caller is not the owner')]
#[should_panic(expected: 'Caller is missing role')]
fn test_audition_registration_config_update_should_panic_on_non_owner() {
let non_owner = test_address();
feign_update_config(non_owner, 1, 10000);
Expand Down
Loading
Loading