Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #154

Merged
merged 65 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
73fce2f
merged files
Orland0x May 10, 2022
487d963
merged space from develop
Orland0x May 10, 2022
1e826de
updated tests
Orland0x May 11, 2022
ccc1515
single slot test with slot key verif
Orland0x May 11, 2022
dcd9914
formatting
Orland0x May 11, 2022
0170b1e
fixed more tests
Orland0x May 12, 2022
7441f0f
fixed more tests
Orland0x May 12, 2022
59d2ca0
single slot strategy added
Orland0x May 13, 2022
cc91a0d
merged quorum stuff
Orland0x May 13, 2022
51784ac
merged quorum stuff
Orland0x May 13, 2022
94d8501
revamped create proposal
Orland0x May 17, 2022
dd68dfb
fixed create vote
Orland0x May 17, 2022
7f02c23
updated eth tx auth
Orland0x May 18, 2022
d4400dc
zodiac test fixes
Orland0x May 18, 2022
63fb02b
zodiac test revamp
Orland0x May 19, 2022
1106d7d
updates
Orland0x May 20, 2022
37301d8
zodiac updates
Orland0x May 22, 2022
eaa6cde
fixed single slot proof strat test
Orland0x May 24, 2022
3443d3c
Update README.md
Orland0x May 24, 2022
300ed55
Update README.md
Orland0x May 24, 2022
27d9beb
fixed controller test
Orland0x May 24, 2022
a8760d1
fixed executor whitelist test
Orland0x May 24, 2022
af5c532
fixed whitelist voting strategytest
Orland0x May 24, 2022
8b02961
fixed merge conflicts
Orland0x May 24, 2022
b45a11b
more merge fixes
Orland0x May 24, 2022
6400a1b
fix l1 tests
Orland0x May 25, 2022
23f4108
Delete vanilla_space.ts
Orland0x May 25, 2022
a02c3bd
Delete vanilla_authenticator.ts
Orland0x May 25, 2022
d9b8619
replaced hardcoded vals with random ones in tests
Orland0x May 25, 2022
ed6f8a5
Merge branch 'revamp_tests' of https://github.com/snapshot-labs/sx-co…
Orland0x May 25, 2022
7421f19
increased timeout
Orland0x May 25, 2022
8d5fb73
OZ naming convention
Orland0x May 25, 2022
1352c11
OZ naming convention
Orland0x May 25, 2022
7c77e22
Delete vanilla.cairo
Orland0x May 25, 2022
e792671
Delete whitelist.cairo
Orland0x May 25, 2022
21a6098
Delete vanilla.cairo
Orland0x May 25, 2022
ad38925
Delete vanilla.cairo
Orland0x May 25, 2022
4b05e99
Delete test_words.cairo
Orland0x May 25, 2022
02bc63d
Delete test_array2d.cairo
Orland0x May 25, 2022
e5c2b97
Delete space.cairo
Orland0x May 26, 2022
5fa8803
Update README.md
Orland0x May 26, 2022
488a863
Update README.md
Orland0x May 26, 2022
3f9635e
removed excess imports
Orland0x May 26, 2022
e524317
Delete contracts/starknet/authenticators directory
Orland0x May 26, 2022
06de52c
Delete contracts/starknet/interfaces directory
Orland0x May 26, 2022
d856f47
GA tests (#153)
Orland0x May 27, 2022
9dac04b
merge
Orland0x May 27, 2022
a408138
Update tests.yml
Orland0x May 27, 2022
ab4e117
Delete contracts/starknet/authenticators directory
Orland0x May 27, 2022
a105e5e
Delete starknet_sig.cairo
Orland0x May 27, 2022
37d5f3a
Delete starknet_tx.cairo
Orland0x May 27, 2022
3998273
Delete eth_tx_auth.ts
Orland0x May 27, 2022
e52e9e0
Delete zodiac.ts
Orland0x May 27, 2022
d6c8d30
Delete executor_whitelist.ts
Orland0x May 27, 2022
6ce9682
Delete starknet_tx_auth.ts
Orland0x May 27, 2022
89e16b8
Delete vanilla_authenticator.ts
Orland0x May 27, 2022
7df1c96
Delete test/starknet/shared directory
Orland0x May 27, 2022
8a98927
updated Stark Tx auth test
Orland0x May 27, 2022
6dfa4a3
use lite mode for devnet
Orland0x May 27, 2022
ad682bb
add timeout for array 2d test
Orland0x May 27, 2022
f131271
increased timeouts
Orland0x May 27, 2022
952f349
fixed zodiac test
Orland0x May 30, 2022
d71c8c7
fixed zodiac module test
Orland0x May 30, 2022
f55d724
fixed hex equivlance issue
Orland0x May 30, 2022
f3a3700
couple of fixes
Orland0x May 31, 2022
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
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ jobs:
run: |
sudo apt install -y libgmp3-dev
python -m pip install --upgrade pip
pip install starknet-devnet==0.2.1
pip install werkzeug==2.0.3
pip install starknet-devnet==0.2.2
pip install openzeppelin-cairo-contracts
pip install marshmallow-dataclass==8.5.3 --force

- name: Compile Contracts
run: yarn compile
Expand Down
56 changes: 53 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,60 @@

# Snapshot X

Programmable governance on StarkNet.

#### [Documentation](https://docs.snapshotx.xyz)
Programmable governance on StarkNet. Refer to the [documentation](https://docs.snapshotx.xyz) for more information.

## Contracts Blueprint
```ml
Orland0x marked this conversation as resolved.
Show resolved Hide resolved
contracts
├─ starknet
│ ├─ Authenticators
│ │ ├─ EthTx.cairo — "Authenticate user via an Ethereum transaction"
│ │ ├─ StarkTx.cairo — "Authenticate user via a StarkNet transaction"
│ │ ├─ StarkSig.cairo — "Authenticate user via a Starknet signature"
│ │ └─ Vanilla.cairo — "Dummy authentication"
│ ├─ VotingStrategies
│ │ ├─ SingleSlotProof.cairo — "Enables the use of the contents of an Ethereum storage slot as voting power"
│ │ ├─ Vanilla.cairo — "Voting power of 1 for every user"
│ │ └─ Whitelist.cairo — "Predetermined voting power for members in a whitelist, otherwise zero"
│ ├─ ExecutionStrategies
│ │ ├─ Vanilla.cairo — "Dummy execution"
│ │ └─ ZodiacRelayer.cairo — "Strategy to execute proposal transactions using an Ethereum Gnosis Safe"
│ ├─ Interfaces
│ │ ├─ IAuthenticator.cairo — "Interface for all authenticators"
│ │ ├─ IExecutionStrategy.cairo — "Interface for all execution strategies"
│ │ └─ IVotingStrategy.cairo — "Interface for all voting strategies"
│ ├─ lib
│ │ ├─ array2d.cairo — "For handling 2 dimensional arrays"
│ │ ├─ choice.cairo — "The set of choices one can make for a vote"
│ │ ├─ eth_address.cairo — "Ethereum address type"
│ │ ├─ felt_to_uint256.cairo — "Convert a felt to a uint256"
│ │ ├─ hash_array.cairo — "Wrapper function for pedersen hashing arrays"
│ │ ├─ proposal.cairo — "Proposal metadata type"
│ │ ├─ proposal_info.cairo — "Proposal vote data type"
│ │ ├─ proposal_outcome.cairo — "The set of proposal outcomes"
│ │ ├─ slot_key.cairo — "Function to find the slot key for a slot in the Ethereum state"
│ │ ├─ vote.cairo.cairo — "User vote data type"
│ │ └─ words.cairo — "Small 64 bit word library"
│ ├─ TestContracts
│ │ ├─ Test_array2d.cairo
│ │ ├─ Test_words.cairo
│ │ └─ Test_words_to_uint256.cairo
│ └─ Space.cairo - "The core contract for Snapshot X"
└─ ethereum
├─ Interfaces
│ └─ IStarknetCore.sol — "Authenticate user via an Ethereum transaction"
├─ StarkNetCommit
│ └─ StarknetCommit.sol — "Authenticate user via an Ethereum transaction"
├─ ZodiacModule
│ ├─ ProposalRelayer.sol — "Authenticate user via an Ethereum transaction"
│ ├─ SnapshotXL1Executor.sol — "Authenticate user via an Ethereum transaction"
│ └─ deps.sol — "No authentication of users"
└─ TestContracts
├─ MockStarknetMessaging.sol — "Authenticate user via an Ethereum transaction"
├─ NamedStorage.sol — "Authenticate user via an Ethereum transaction"
└─ StarknetMessaging.sol — "No authentication of users"

```

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
pragma solidity 0.8.9;

import '@gnosis.pm/zodiac/contracts/guard/Guardable.sol';
import '../Interfaces/IStarknetCore.sol';
// import '../Interfaces/IStarknetCore.sol';

import 'contracts/ethereum/TestContracts/MockStarknetMessaging.sol';

/**
* @title Snapshot X L1 Proposal Relayer
Expand All @@ -12,7 +14,9 @@ import '../Interfaces/IStarknetCore.sol';
*/
contract SnapshotXProposalRelayer is Guardable {
/// The StarkNet Core contract
IStarknetCore public starknetCore;
// IStarknetCore public starknetCore;

MockStarknetMessaging public starknetCore;

/// Address of the StarkNet contract that will send execution details to this contract in a L2 -> L1 message
uint256 public l2ExecutionRelayer;
Expand All @@ -23,15 +27,22 @@ contract SnapshotXProposalRelayer is Guardable {
*/
event ChangedL2ExecutionRelayer(uint256 _l2ExecutionRelayer);

/**
* @dev Initialization of the functionality. Called internally by the setUp function
* @param _starknetCore Address of the StarkNet Core contract
* @param _l2ExecutionRelayer Address of the new execution relayer contract
*/
// /**
// * @dev Initialization of the functionality. Called internally by the setUp function
// * @param _starknetCore Address of the StarkNet Core contract
// * @param _l2ExecutionRelayer Address of the new execution relayer contract
// */
// function setUpSnapshotXProposalRelayer(address _starknetCore, uint256 _l2ExecutionRelayer)
// internal
// {
// starknetCore = IStarknetCore(_starknetCore);
// l2ExecutionRelayer = _l2ExecutionRelayer;
// }

function setUpSnapshotXProposalRelayer(address _starknetCore, uint256 _l2ExecutionRelayer)
internal
{
starknetCore = IStarknetCore(_starknetCore);
starknetCore = MockStarknetMessaging(_starknetCore);
l2ExecutionRelayer = _l2ExecutionRelayer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ contract SnapshotXL1Executor is Module, SnapshotXProposalRelayer {
uint256 executionHashHigh,
bytes32[] memory _txHashes
) external {
//External call will fail if finalized proposal message was not received on L1.
_receiveFinalizedProposal(callerAddress, proposalOutcome, executionHashLow, executionHashHigh);
require(whitelistedSpaces[callerAddress] == true, 'Invalid caller');
require(proposalOutcome != 0, 'Proposal did not pass');
require(_txHashes.length > 0, 'proposal must contain transactions');
require(whitelistedSpaces[callerAddress] == true, 'Invalid caller');

//External call will fail if finalized proposal message was not received on L1.
_receiveFinalizedProposal(callerAddress, proposalOutcome, executionHashLow, executionHashHigh);

// Re-assemble the lowest and highest bytes to get the full execution hash
uint256 executionHash = (executionHashHigh << 128) + executionHashLow;
Expand Down
13 changes: 13 additions & 0 deletions contracts/starknet/ExecutionStrategies/Vanilla.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%lang starknet

from starkware.cairo.common.uint256 import Uint256

@external
func execute{syscall_ptr : felt*}(
proposal_outcome : felt,
execution_hash : Uint256,
execution_params_len : felt,
execution_params : felt*,
):
return ()
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%lang starknet

@contract_interface
namespace i_authenticator:
namespace IAuthenticator:
func execute(target : felt, function_selector : felt, calldata_len : felt, calldata : felt*):
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from contracts.starknet.lib.eth_address import EthAddress
from starkware.cairo.common.uint256 import Uint256

@contract_interface
namespace i_execution_strategy:
namespace IExecutionStrategy:
func execute(
proposal_outcome : felt,
execution_hash : Uint256,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from contracts.starknet.lib.eth_address import EthAddress
from starkware.cairo.common.uint256 import Uint256

@contract_interface
namespace i_voting_strategy:
namespace IVotingStrategy:
func get_voting_power(
block : felt,
voter_address : EthAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ from starkware.cairo.common.math import (
assert_lt_felt,
)

from contracts.starknet.interfaces.i_voting_strategy import i_voting_strategy
from contracts.starknet.interfaces.i_execution_strategy import i_execution_strategy
from contracts.starknet.Interfaces.IVotingStrategy import IVotingStrategy
from contracts.starknet.Interfaces.IExecutionStrategy import IExecutionStrategy
from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.proposal import Proposal
from contracts.starknet.lib.proposal_info import ProposalInfo
Expand Down Expand Up @@ -426,7 +426,7 @@ func get_cumulative_voting_power{syscall_ptr : felt*, pedersen_ptr : HashBuiltin
user_voting_strategy_params_all, index
)

let (user_voting_power) = i_voting_strategy.get_voting_power(
let (user_voting_power) = IVotingStrategy.get_voting_power(
contract_address=voting_strategy,
block=current_timestamp,
voter_address=voter_address,
Expand Down Expand Up @@ -921,7 +921,7 @@ func finalize_proposal{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_c
tempvar proposal_outcome = proposal_outcome
end

i_execution_strategy.execute(
IExecutionStrategy.execute(
contract_address=proposal.executor,
proposal_outcome=proposal_outcome,
execution_hash=proposal.execution_hash,
Expand Down Expand Up @@ -964,7 +964,7 @@ func cancel_proposal{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_che

let proposal_outcome = ProposalOutcome.CANCELLED

i_execution_strategy.execute(
IExecutionStrategy.execute(
contract_address=proposal.executor,
proposal_outcome=proposal_outcome,
execution_hash=proposal.execution_hash,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
%lang starknet
from starkware.cairo.common.uint256 import Uint256
from starknet.lib.words64_to_uint256 import words64_to_uint256
from starknet.lib.words import words_to_uint256

@view
func test_words64_to_uint256{range_check_ptr}(
func test_words_to_uint256{range_check_ptr}(
word1 : felt, word2 : felt, word3 : felt, word4 : felt
) -> (uint256 : Uint256):
let (uint256) = words64_to_uint256(word1, word2, word3, word4)
let (uint256) = words_to_uint256(word1, word2, word3, word4)
return (uint256)
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from starkware.cairo.common.math import unsigned_div_rem, assert_nn_le
from contracts.starknet.fossil.contracts.starknet.types import StorageSlot
from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.slot_key import get_slot_key
from contracts.starknet.lib.words64_to_uint256 import words64_to_uint256
from contracts.starknet.lib.words import words_to_uint256

# FactRegistry simplified interface
@contract_interface
Expand Down Expand Up @@ -74,7 +74,7 @@ func get_voting_power{

# Checking slot proof is for the correct slot
let (valid_slot) = get_slot_key(slot_index, voter_address.value)
let (slot_uint256) = words64_to_uint256(slot.word_1, slot.word_2, slot.word_3, slot.word_4)
let (slot_uint256) = words_to_uint256(slot.word_1, slot.word_2, slot.word_3, slot.word_4)
with_attr error_message("Invalid slot proof provided"):
assert valid_slot = slot_uint256
end
Expand Down
1 change: 0 additions & 1 deletion contracts/starknet/lib/array2d.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func construct_array2d{range_check_ptr}(flat_array_len : felt, flat_array : felt
return (array2d)
end

# Extracts sub array from 2d array at postion specified by index
func get_sub_array{range_check_ptr}(array2d : Immutable2DArray, index : felt) -> (
array_len : felt, array : felt*
):
Expand Down
11 changes: 11 additions & 0 deletions contracts/starknet/lib/words.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.math import unsigned_div_rem
from starkware.cairo.common.bitwise import bitwise_and
from starkware.cairo.common.uint256 import Uint256

const MASK_4 = 2 ** 64 - 1
const MASK_3 = 2 ** 128 - 2 ** 64
Expand Down Expand Up @@ -37,3 +38,13 @@ func felt_to_words{bitwise_ptr : BitwiseBuiltin*, range_check_ptr}(value : felt)

return (Words(word_1, word_2, word_3, word_4))
end

# Convert 4 words of 8 bytes each to a Uint256
# Word 1 is the most significant word and word 4 is the least significant word
func words_to_uint256{range_check_ptr}(word1 : felt, word2 : felt, word3 : felt, word4 : felt) -> (
uint256 : Uint256
):
let word1_shifted = word1 * SHIFT_64
let word3_shifted = word3 * SHIFT_64
return (Uint256(low=word3_shifted + word4, high=word1_shifted + word2))
end
13 changes: 0 additions & 13 deletions contracts/starknet/lib/words64_to_uint256.cairo

This file was deleted.

1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const config: HardhatUserConfig = {
},
ethereumLocal: {
url: 'http://localhost:8545',
chainId: 31337,
},
starknetLocal: {
url: 'http://localhost:8000',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test:crosschain": "'./scripts/test-crosschain.sh'",
"test:crosschain:ci": "concurrently './scripts/chain.sh' './scripts/test-crosschain.sh'",
"chain:l1": "hardhat node",
"chain:l2": "starknet-devnet -p 8000",
"chain:l2": "starknet-devnet -p 8000 --lite-mode",
"chain": "concurrently 'yarn chain:l1' 'yarn chain:l2'",
"format:l1": "prettier --write 'contracts/**/*.sol'",
"check-format:l1": "prettier -c 'contracts/**/*.sol'",
Expand Down Expand Up @@ -43,7 +43,7 @@
"@nomiclabs/hardhat-etherscan": "^3.0.3",
"@nomiclabs/hardhat-solhint": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@shardlabs/starknet-hardhat-plugin": "^0.5.3",
"@shardlabs/starknet-hardhat-plugin": "^0.5.5",
"@typechain/ethers-v5": "^7.2.0",
"@typechain/hardhat": "^2.3.1",
"@types/chai": "^4.3.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-crosschain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

yarn wait-on tcp:8000 &&
wait-on tcp:8545 &&
yarn hardhat test test/crosschain/zodiac.ts --network 'ethereumLocal' --starknet-network 'starknetLocal' &&
yarn hardhat test test/crosschain/ZodiacExecution.test.ts --network 'ethereumLocal' --starknet-network 'starknetLocal' &&
sleep 10 &&
yarn hardhat test test/crosschain/eth_tx_auth.ts --network 'ethereumLocal' --starknet-network 'starknetLocal'
yarn hardhat test test/crosschain/EthTxAuth.test.ts --network 'ethereumLocal' --starknet-network 'starknetLocal'
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:8545)
Expand Down
Loading