Skip to content

Commit

Permalink
Env vars ci (#404)
Browse files Browse the repository at this point in the history
* feat: updated example env files

* feat: added fallback values

* ci: updated ci start command

* ci: wrapped start command in quotes

* feat: removed unused envs

* ci: disable e2e

* ci: comment out job
  • Loading branch information
MrX-SNX authored Aug 21, 2024
1 parent 9153540 commit b39654c
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 95 deletions.
108 changes: 54 additions & 54 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,56 +120,56 @@ jobs:
- run: git diff --name-only --exit-code
- run: yarn typecheck

governance-e2e:
working_directory: /tmp/app
docker:
- image: cypress/included:<< pipeline.parameters.cypress-version >>
resource_class: large
environment:
NODE_ENV: test
TESTNET: 1
steps:
- checkout
- install-foundry
- yarn-install

- run:
name: Run server localhost:3000
working_directory: /tmp/app/governance/ui
command: DEV=false TESTNET=false CI=true yarn start
background: true

- run:
name: Run anvil localhost:8545
command: 'anvil --fork-url https://testnet.snaxchain.io'
background: true

- run:
name: Wait for server localhost:3000
command: wget --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 http://localhost:3000

- run:
name: Wait for anvil localhost:8545
command: wget -q -O - --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 --post-data='{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}' --header='Content-Type:application/json' http://localhost:8545

- run:
working_directory: /tmp/app/governance/cypress
command: cypress run --e2e --browser chrome

- store_test_results:
path: 'governance/cypress/cypress/reports'

- store_artifacts:
path: 'governance/cypress/.nyc_output'
destination: 'coverage'

- store_artifacts:
path: 'governance/cypress/cypress/screenshots'
destination: 'screenshots'

- store_artifacts:
path: 'governance/cypress/cypress/videos'
destination: 'videos'
# governance-e2e:
# working_directory: /tmp/app
# docker:
# - image: cypress/included:<< pipeline.parameters.cypress-version >>
# resource_class: large
# environment:
# NODE_ENV: test
# TESTNET: 1
# steps:
# - checkout
# - install-foundry
# - yarn-install

# - run:
# name: Run server localhost:3000
# working_directory: /tmp/app/governance/ui
# command: CI=true yarn start
# background: true

# - run:
# name: Run anvil localhost:8545
# command: 'anvil --fork-url https://testnet.snaxchain.io --fork-block-number 296528'
# background: true

# - run:
# name: Wait for server localhost:3000
# command: wget --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 http://localhost:3000

# - run:
# name: Wait for anvil localhost:8545
# command: wget -q -O - --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 --post-data='{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}' --header='Content-Type:application/json' http://localhost:8545

# - run:
# working_directory: /tmp/app/governance/cypress
# command: cypress run --e2e --browser chrome

# - store_test_results:
# path: 'governance/cypress/cypress/reports'

# - store_artifacts:
# path: 'governance/cypress/.nyc_output'
# destination: 'coverage'

# - store_artifacts:
# path: 'governance/cypress/cypress/screenshots'
# destination: 'screenshots'

# - store_artifacts:
# path: 'governance/cypress/cypress/videos'
# destination: 'videos'

liquidity-e2e:
parameters:
Expand Down Expand Up @@ -269,7 +269,7 @@ jobs:
- run: rm -rf /tmp/cov
- run: yarn download-cci-coverage tests /tmp/cov || true
- run: yarn download-cci-coverage liquidity-cy /tmp/cov || true
- run: yarn download-cci-coverage governance-cy /tmp/cov || true
# - run: yarn download-cci-coverage governance-cy /tmp/cov || true
- run: yarn download-cci-coverage liquidity-e2e-base-mainnet /tmp/cov || true
- run: yarn download-cci-coverage liquidity-e2e-optimism-mainnet /tmp/cov || true
- run: mkdir -p /tmp/cov
Expand Down Expand Up @@ -307,8 +307,8 @@ workflows:
- typecheck
- tests
- liquidity-cy
- governance-e2e:
name: governance-e2e-snax-testnet
# - governance-e2e:
# name: governance-e2e-snax-testnet
- liquidity-e2e:
name: liquidity-e2e-base-mainnet
chainId: 8453
Expand All @@ -323,7 +323,7 @@ workflows:
requires: [
tests,
liquidity-cy,
governance-e2e-snax-testnet,
# governance-e2e-snax-testnet,
liquidity-e2e-base-mainnet,
#liquidity-e2e-sepolia,
]
Expand Down
8 changes: 3 additions & 5 deletions governance/ui/.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
INFURA_KEY=xxx
WC_PROJECT_ID=xxx
BOARDROOM_KEY=xxx
WC_PROJECT_ID=5075a2da602e17eec34aa77b40b321be
BOARDROOM_KEY=d9abe7a1ab45ace58e6bd91bb9771586
DEV=false
DEV_RPC_MOTHERSHIP=http://127.0.0.1:19000
TESTNET=false
CI=true
CI=false
CI_RPC_MOTHERSHIP=http://127.0.0.1:8545
6 changes: 4 additions & 2 deletions governance/ui/src/queries/useGetCouncilMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { getCouncilContract } from '../utils/contracts';
import { motherShipProvider } from '../utils/providers';
import { useNetwork } from './useWallet';

export function useGetCouncilMembers(council: CouncilSlugs) {
const { network } = useNetwork();
return useQuery({
queryKey: ['members', council],
queryKey: ['members', council, network?.id],
queryFn: async () => {
const members = (await getCouncilContract(council)
.connect(motherShipProvider)
.connect(motherShipProvider(network?.id))
.getCouncilMembers()) as string[];
return members;
},
Expand Down
6 changes: 4 additions & 2 deletions governance/ui/src/queries/useGetCouncilNominees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { motherShipProvider } from '../utils/providers';
import { getCouncilContract } from '../utils/contracts';
import { useNetwork } from './useWallet';

export function useGetCouncilNominees(council: CouncilSlugs) {
const { network } = useNetwork();
return useQuery({
queryKey: ['nominees', council],
queryKey: ['nominees', council, network?.id],
queryFn: async () => {
return (await getCouncilContract(council)
.connect(motherShipProvider)
.connect(motherShipProvider(network?.id))
.getNominees()) as string[];
},
enabled: !!council,
Expand Down
8 changes: 6 additions & 2 deletions governance/ui/src/queries/useGetCurrentPeriod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { motherShipProvider } from '../utils/providers';
import { getCouncilContract } from '../utils/contracts';
import { useNetwork } from './useWallet';

export function useGetCurrentPeriod(council?: CouncilSlugs) {
const { network } = useNetwork();
return useQuery({
queryKey: ['period', council],
queryKey: ['period', council, network?.id],
queryFn: async () => {
return (
await getCouncilContract(council!).connect(motherShipProvider).getCurrentPeriod()
await getCouncilContract(council!)
.connect(motherShipProvider(network?.id))
.getCurrentPeriod()
).toString() as string | undefined;
},
enabled: !!council,
Expand Down
6 changes: 3 additions & 3 deletions governance/ui/src/queries/useGetElectionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { getCouncilContract } from '../utils/contracts';
import { useSigner } from '@snx-v3/useBlockchain';
import { motherShipProvider } from '../utils/providers';
import { useNetwork } from './useWallet';

export function useGetElectionSettings(council: CouncilSlugs) {
const signer = useSigner();
const { network } = useNetwork();
return useQuery({
queryKey: ['useGetElectionSettings', council],
queryFn: async () => {
return (await getCouncilContract(council)
.connect(signer ? signer : motherShipProvider)
.connect(motherShipProvider(network?.id))
.getElectionSettings()) as Promise<{
epochSeatCount: number;
minimumActiveMembers: number;
Expand Down
8 changes: 4 additions & 4 deletions governance/ui/src/queries/useGetEpochSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { motherShipProvider } from '../utils/providers';
import { getCouncilContract } from '../utils/contracts';
import { useProvider } from './useWallet';
import { useNetwork } from './useWallet';

export function useGetEpochSchedule(council?: CouncilSlugs) {
const provider = useProvider();
const { network } = useNetwork();

return useQuery({
queryKey: ['epoch-schedule', council],
queryKey: ['epoch-schedule', council, network?.id],
queryFn: async () => {
const schedule = await getCouncilContract(council!)
.connect(provider ? provider : motherShipProvider)
.connect(motherShipProvider(network?.id))
.getEpochSchedule();
return {
startDate: Number(schedule.startDate.toString()),
Expand Down
11 changes: 7 additions & 4 deletions governance/ui/src/queries/useGetIsNominated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import { motherShipProvider } from '../utils/providers';
import councils from '../utils/councils';
import { getCouncilContract } from '../utils/contracts';
import { utils } from 'ethers';
import { useNetwork } from './useWallet';

export function useGetIsNominated(address?: string) {
const { network } = useNetwork();
return useQuery({
queryKey: ['isNominated', address],
queryKey: ['isNominated', address, network?.id],
queryFn: async () => {
const provider = motherShipProvider(network?.id);
const isNominatedForSpartanCouncil = (await getCouncilContract('spartan')
.connect(motherShipProvider)
.connect(provider)
.isNominated(address)) as boolean | undefined;
const isNominatedForAmbassadorCouncil = (await getCouncilContract('ambassador')
.connect(motherShipProvider)
.connect(provider)
.isNominated(address)) as boolean | undefined;
const isNominatedForTreasuryCouncil = (await getCouncilContract('treasury')
.connect(motherShipProvider)
.connect(provider)
.isNominated(address)) as boolean | undefined;
return {
isNominated:
Expand Down
4 changes: 3 additions & 1 deletion governance/ui/src/queries/useGetNextElectionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { useQuery } from '@tanstack/react-query';
import { CouncilSlugs } from '../utils/councils';
import { motherShipProvider } from '../utils/providers';
import { getCouncilContract } from '../utils/contracts';
import { useNetwork } from './useWallet';

export function useGetNextElectionSettings(council: CouncilSlugs) {
const { network } = useNetwork();
return useQuery({
queryKey: ['next-epoch-settings', council],
queryFn: async () => {
const schedule = await getCouncilContract(council)
.connect(motherShipProvider)
.connect(motherShipProvider(network?.id))
.getNextElectionSettings();
return Number(schedule.epochDuration.toString()) as number | undefined;
},
Expand Down
5 changes: 3 additions & 2 deletions governance/ui/src/queries/useGetUserBallot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ async function getBallot<T extends CouncilSlugs | CouncilSlugs[]>(
council: CouncilSlugs;
}[]
> {
const provider = motherShipProvider(chainId);
let ballot;
if (Array.isArray(council)) {
ballot = (await Promise.all(
council.map(async (c) => {
const electionModule = getCouncilContract(c).connect(motherShipProvider);
const electionModule = getCouncilContract(c).connect(provider);
const electionId = await electionModule.getEpochIndex();
const temp = await electionModule.getBallot(address, chainId, electionId);
return { ...temp, council: c };
})
)) as { votingPower: BigNumber; votedCandidates: string[]; amounts: BigNumber[] }[];
} else {
const electionModule = getCouncilContract(council).connect(motherShipProvider);
const electionModule = getCouncilContract(council).connect(provider);
const electionId = electionModule.getEpochIndex();
const temp = (await electionModule.getBallot(address, chainId, electionId)) as {
votingPower: BigNumber;
Expand Down
2 changes: 1 addition & 1 deletion governance/ui/src/queries/useGetUserVotingPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useGetUserVotingPower(council: CouncilSlugs) {
if (!activeWallet || !provider || !network?.id) return;

try {
const electionModule = getCouncilContract(council).connect(motherShipProvider);
const electionModule = getCouncilContract(council).connect(motherShipProvider(network.id));
const isMotherchain = network.id === (process.env.CI === 'true' ? 13001 : 2192);

const electionId = await electionModule.getEpochIndex();
Expand Down
3 changes: 2 additions & 1 deletion governance/ui/src/queries/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ export function useSigner() {

export function useProvider() {
const [{ wallet }] = useConnectWallet();
const { network } = useNetwork();

if (!wallet) {
return motherShipProvider;
return motherShipProvider(network?.id);
}

const provider = new ethers.providers.Web3Provider(wallet.provider, 'any');
Expand Down
12 changes: 6 additions & 6 deletions governance/ui/src/utils/providers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { providers } from 'ethers';

export const motherShipProvider = new providers.JsonRpcProvider(
process.env.DEV === 'true'
? process.env.DEV_RPC_MOTHERSHIP
: process.env.CI === 'true'
export const motherShipProvider = (networkId?: number) => {
return new providers.JsonRpcProvider(
process.env.CI === 'true'
? process.env.CI_RPC_MOTHERSHIP
: process.env.TESTNET === 'true'
: networkId === 13001
? 'https://testnet.snaxchain.io/'
: 'https://mainnet.snaxchain.io/'
);
);
};
18 changes: 10 additions & 8 deletions governance/ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,16 @@ module.exports = {
)
.concat(
new webpack.DefinePlugin({
'process.env.INFURA_KEY': JSON.stringify(process.env.INFURA_KEY),
'process.env.DEV': JSON.stringify(process.env.DEV),
'process.env.CI': JSON.stringify(process.env.CI),
'process.env.CI_RPC_MOTHERSHIP': JSON.stringify(process.env.CI_RPC_MOTHERSHIP),
'process.env.DEV_RPC_MOTHERSHIP': JSON.stringify(process.env.DEV_RPC_MOTHERSHIP),
'process.env.TESTNET': JSON.stringify(process.env.TESTNET),
'process.env.WC_PROJECT_ID': JSON.stringify(process.env.WC_PROJECT_ID),
'process.env.BOARDROOM_KEY': JSON.stringify(process.env.BOARDROOM_KEY),
'process.env.DEV': JSON.stringify(process.env.DEV) || 'false',
'process.env.CI': JSON.stringify(process.env.CI) || 'false',
'process.env.CI_RPC_MOTHERSHIP':
JSON.stringify(process.env.CI_RPC_MOTHERSHIP) || 'http://127.0.0.1:8545',
'process.env.DEV_RPC_MOTHERSHIP':
JSON.stringify(process.env.DEV_RPC_MOTHERSHIP) || 'http://127.0.0.1:19000',
'process.env.WC_PROJECT_ID':
JSON.stringify(process.env.WC_PROJECT_ID) || '5075a2da602e17eec34aa77b40b321be',
'process.env.BOARDROOM_KEY':
JSON.stringify(process.env.BOARDROOM_KEY) || 'd9abe7a1ab45ace58e6bd91bb9771586',
})
),
resolve: {
Expand Down

0 comments on commit b39654c

Please sign in to comment.