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

Move utilities to sx.js #219

Merged
merged 5 commits into from
Jul 12, 2022
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
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ jobs:
sudo apt install -y libgmp3-dev
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install werkzeug==2.0.3
pip install marshmallow-dataclass==8.5.3 --force

- name: Run Linters
run: yarn check-format
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
run: |
sudo apt install -y libgmp3-dev
python -m pip install --upgrade pip
pip install starknet-devnet==0.2.2
pip install openzeppelin-cairo-contracts
pip install -r requirements.txt
pip install starknet-devnet

- name: Compile Contracts
run: yarn compile
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ artifacts
starknet-artifacts
factories
typechain
typechain-types

.yarn
.env
Expand Down
2 changes: 1 addition & 1 deletion contracts/starknet/fossil
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"@gnosis.pm/safe-contracts": "^1.3.0",
"@gnosis.pm/zodiac": "^1.0.11",
"@openzeppelin/contracts": "^4.7.0",
"@shardlabs/starknet-hardhat-plugin": "^0.5.5",
"@snapshot-labs/sx": "0.1.0-beta.7",
"concurrently": "^7.2.2",
"ethereumjs-util": "^7.1.5",
"install": "^0.13.0",
Expand All @@ -47,7 +49,6 @@
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-solhint": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@shardlabs/starknet-hardhat-plugin": "^0.5.5",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://github.com/starkware-libs/cairo-lang/releases/download/v0.9.0/cairo-lang-0.9.0.zip
openzeppelin-cairo-contracts
openzeppelin-cairo-contracts==0.1.0
15 changes: 7 additions & 8 deletions test/crosschain/EthTxAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { expect } from 'chai';
import { Contract } from 'ethers';
import { starknet, network, ethers } from 'hardhat';
import { StarknetContract, Account, HttpNetworkConfig } from 'hardhat/types';
import { strToShortStringArr } from '@snapshot-labs/sx';
import { getCommit, getProposeCalldata } from '../shared/helpers';
import { utils } from '@snapshot-labs/sx';
import { ethTxAuthSetup } from '../shared/setup';
import { PROPOSE_SELECTOR } from '../shared/constants';

Expand Down Expand Up @@ -46,7 +45,7 @@ describe('L1 interaction with Snapshot X', function () {
starknetCommit,
} = await ethTxAuthSetup());

metadataUri = strToShortStringArr(
metadataUri = utils.strings.strToShortStringArr(
'Hello and welcome to Snapshot X. This is the future of governance.'
);
proposerEthAddress = signer.address;
Expand All @@ -55,7 +54,7 @@ describe('L1 interaction with Snapshot X', function () {
userVotingParamsAll = [[]];
executionStrategy = BigInt(vanillaExecutionStrategy.address);
executionParams = [];
proposeCalldata = getProposeCalldata(
proposeCalldata = utils.encoding.getProposeCalldata(
proposerEthAddress,
metadataUri,
executionStrategy,
Expand All @@ -70,7 +69,7 @@ describe('L1 interaction with Snapshot X', function () {
// Committing the hash of the payload to the StarkNet Commit L1 contract
await starknetCommit
.connect(signer)
.commit(getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata));
.commit(utils.encoding.getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata));
// Checking that the L1 -> L2 message has been propogated
expect((await starknet.devnet.flush()).consumed_messages.from_l1).to.have.a.lengthOf(1);
// Creating proposal
Expand All @@ -85,7 +84,7 @@ describe('L1 interaction with Snapshot X', function () {
await starknet.devnet.loadL1MessagingContract(networkUrl, mockStarknetMessaging.address);
await starknetCommit
.connect(signer)
.commit(getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata));
.commit(utils.encoding.getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata));
await starknet.devnet.flush();
await ethTxAuthenticator.invoke('authenticate', {
target: spaceAddress,
Expand All @@ -108,7 +107,7 @@ describe('L1 interaction with Snapshot X', function () {
await starknet.devnet.loadL1MessagingContract(networkUrl, mockStarknetMessaging.address);
await starknetCommit
.connect(signer)
.commit(getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata)); // Wrong selector
.commit(utils.encoding.getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata)); // Wrong selector
await starknet.devnet.flush();
try {
await ethTxAuthenticator.invoke('authenticate', {
Expand All @@ -126,7 +125,7 @@ describe('L1 interaction with Snapshot X', function () {
proposeCalldata[0] = BigInt(ethers.Wallet.createRandom().address); // Random l1 address in the calldata
await starknetCommit
.connect(signer)
.commit(getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata));
.commit(utils.encoding.getCommit(spaceAddress, PROPOSE_SELECTOR, proposeCalldata));
await starknet.devnet.flush();
try {
await ethTxAuthenticator.invoke('authenticate', {
Expand Down
39 changes: 18 additions & 21 deletions test/crosschain/ZodiacExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import hre, { starknet, network } from 'hardhat';
import { Choice, SplitUint256 } from '../shared/types';
import { StarknetContract, HttpNetworkConfig, Account } from 'hardhat/types';
import { strToShortStringArr } from '@snapshot-labs/sx';
import { utils } from '@snapshot-labs/sx';
import { zodiacRelayerSetup } from '../shared/setup';
import {
createExecutionHash,
expectAddressEquality,
getProposeCalldata,
getVoteCalldata,
} from '../shared/helpers';
import { PROPOSE_SELECTOR, VOTE_SELECTOR } from '../shared/constants';

const VITALIK_ADDRESS = 'd8da6bf26964af9d7eed9e03e53415d37aa96045'; //removed hex prefix

// Dummy tx
const tx1 = {
const tx1: utils.encoding.MetaTransaction = {
to: VITALIK_ADDRESS,
value: 0,
data: '0x11',
Expand All @@ -26,7 +19,7 @@ const tx1 = {
};

// Dummy tx 2
const tx2 = {
const tx2: utils.encoding.MetaTransaction = {
to: VITALIK_ADDRESS,
value: 0,
data: '0x22',
Expand Down Expand Up @@ -62,7 +55,7 @@ describe('Create proposal, cast vote, and send execution to l1', function () {
// Additional parameters for voting
let voterEthAddress: string;
let proposalId: bigint;
let choice: Choice;
let choice: utils.choice.Choice;
let usedVotingStrategies2: bigint[];
let userVotingParamsAll2: bigint[][];
let voteCalldata: bigint[];
Expand All @@ -84,10 +77,14 @@ describe('Create proposal, cast vote, and send execution to l1', function () {
mockStarknetMessaging,
} = await zodiacRelayerSetup());

metadataUri = strToShortStringArr(
metadataUri = utils.strings.strToShortStringArr(
'Hello and welcome to Snapshot X. This is the future of governance.'
);
({ executionHash, txHashes } = createExecutionHash(zodiacModule.address, tx1, tx2));
({ executionHash, txHashes } = utils.encoding.createExecutionHash(
[tx1, tx2],
zodiacModule.address,
network.config.chainId!
));

proposerEthAddress = signer.address;
spaceAddress = BigInt(space.address);
Expand All @@ -96,11 +93,11 @@ describe('Create proposal, cast vote, and send execution to l1', function () {
executionStrategy = BigInt(zodiacRelayer.address);
executionParams = [
BigInt(zodiacModule.address),
SplitUint256.fromHex(executionHash).low,
SplitUint256.fromHex(executionHash).high,
utils.splitUint256.SplitUint256.fromHex(executionHash).low,
utils.splitUint256.SplitUint256.fromHex(executionHash).high,
];

proposeCalldata = getProposeCalldata(
proposeCalldata = utils.encoding.getProposeCalldata(
proposerEthAddress,
metadataUri,
executionStrategy,
Expand All @@ -112,10 +109,10 @@ describe('Create proposal, cast vote, and send execution to l1', function () {
voterEthAddress = hre.ethers.Wallet.createRandom().address;

proposalId = BigInt(1);
choice = Choice.FOR;
choice = utils.choice.Choice.FOR;
usedVotingStrategies2 = [BigInt(vanillaVotingStrategy.address)];
userVotingParamsAll2 = [[]];
voteCalldata = getVoteCalldata(
voteCalldata = utils.encoding.getVoteCalldata(
voterEthAddress,
proposalId,
choice,
Expand Down Expand Up @@ -157,16 +154,16 @@ describe('Create proposal, cast vote, and send execution to l1', function () {
expect(flushL2Response.consumed_messages.from_l1).to.be.empty;
const flushL2Messages = flushL2Response.consumed_messages.from_l2;
expect(flushL2Messages).to.have.a.lengthOf(1);
expectAddressEquality(flushL2Messages[0].from_address, zodiacRelayer.address);
expectAddressEquality(flushL2Messages[0].to_address, zodiacModule.address);
expect(BigInt(flushL2Messages[0].from_address)).to.equal(BigInt(zodiacRelayer.address));
expect(BigInt(flushL2Messages[0].to_address)).to.equal(BigInt(zodiacModule.address));

// -- Check that l1 can receive the proposal correctly --

const proposalOutcome = BigInt(1);
const fakeTxHashes = txHashes.slice(0, -1);
const callerAddress = BigInt(space.address);
const fakeCallerAddress = BigInt(zodiacRelayer.address);
const splitExecutionHash = SplitUint256.fromHex(executionHash);
const splitExecutionHash = utils.splitUint256.SplitUint256.fromHex(executionHash);

// Check that if the tx hash is incorrect, the transaction reverts.
await expect(
Expand Down
Loading