Skip to content

Commit

Permalink
add invalid payload test for execute
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Aug 31, 2023
1 parent b09524b commit 6bff80e
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions starknet/src/tests/test_space.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,41 @@ mod tests {
space.execute(u256_from_felt252(1), vanilla_execution_strategy.params.clone());
}

#[test]
#[available_gas(10000000000)]
#[should_panic(expected: ('Invalid payload hash', 'ENTRYPOINT_FAILED'))]
fn execute_invalid_payload() {
let config = setup();
let (factory, space) = deploy(@config);

let authenticator = IVanillaAuthenticatorDispatcher {
contract_address: *config.authenticators.at(0),
};

let (executor_address, _) = deploy_syscall(
ExecutorWithoutTxExecutionStrategy::TEST_CLASS_HASH.try_into().unwrap(),
0,
array![].span(),
false
)
.unwrap();
let execution_strategy = StrategyImpl::from_address(executor_address);
let author = UserAddress::Starknet(contract_address_const::<0x5678>());
let mut propose_calldata = array![];
author.serialize(ref propose_calldata);
ArrayTrait::<felt252>::new().serialize(ref propose_calldata);
execution_strategy.serialize(ref propose_calldata);
ArrayTrait::<felt252>::new().serialize(ref propose_calldata);

// Create Proposal
authenticator.authenticate(space.contract_address, PROPOSE_SELECTOR, propose_calldata);

testing::set_block_timestamp(config.voting_delay + config.max_voting_duration);

// Execute Proposal
space.execute(1, array!['random', 'stuff']);
}

#[test]
#[available_gas(10000000000)]
#[should_panic(expected: ('Proposal has been finalized', 'ENTRYPOINT_FAILED'))]
Expand All @@ -514,25 +549,19 @@ mod tests {
contract_address: *config.authenticators.at(0)
};

let quorum = u256_from_felt252(1);
let mut constructor_calldata = array![];
quorum.serialize(ref constructor_calldata);

let (vanilla_execution_strategy_address, _) = deploy_syscall(
VanillaExecutionStrategy::TEST_CLASS_HASH.try_into().unwrap(),
let (executor_address, _) = deploy_syscall(
ExecutorWithoutTxExecutionStrategy::TEST_CLASS_HASH.try_into().unwrap(),
0,
constructor_calldata.span(),
array![].span(),
false
)
.unwrap();
let vanilla_execution_strategy = StrategyImpl::from_address(
vanilla_execution_strategy_address
);
let execution_strategy = StrategyImpl::from_address(executor_address);
let mut propose_calldata = array![];
let author = UserAddress::Starknet(contract_address_const::<0x5678>());
author.serialize(ref propose_calldata);
ArrayTrait::<felt252>::new().serialize(ref propose_calldata);
vanilla_execution_strategy.serialize(ref propose_calldata);
execution_strategy.serialize(ref propose_calldata);
ArrayTrait::<felt252>::new().serialize(ref propose_calldata);

// Create Proposal
Expand Down

0 comments on commit 6bff80e

Please sign in to comment.