Skip to content

Commit

Permalink
Local fork deployment test for andromeda
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Nov 17, 2023
1 parent fcc9103 commit 437b772
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 143 deletions.
37 changes: 33 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,42 @@ jobs:
- install-anvil
- run-anvil:
chain: base-goerli
- install-ipfs
- run-ipfs
#- install-ipfs
#- run-ipfs
- yarn-install
- wait-for-anvil
- wait-for-ipfs
#- wait-for-ipfs

- run: echo "OK"
- run:
name: "Generate upgrade transactions"
command: |
yarn cannon build \
omnibus-base-goerli-andromeda.toml \
--dry-run \
--preset andromeda \
--upgrade-from synthetix-omnibus:latest \
--chain-id 84531 \
--provider-url https://base-goerli.infura.io/v3/$INFURA_API_KEY \
--write-script ./e2e/upgrade--base-goerli-andromeda.json \
--write-script-format json
yarn prettier --write ./e2e/upgrade--base-goerli-andromeda.json
- run:
name: "Generate deployments"
command: node e2e/fetch-local-deployment.js 84531 omnibus-base-goerli-andromeda.toml

- store_artifacts:
path: "./e2e/upgrade--base-goerli-andromeda.json"

- run:
name: "Upgrade on local fork"
command: node e2e/deploy.js ./e2e/upgrade--base-goerli-andromeda.json

- run:
name: "Run tests"
environment:
- DEBUG: "tasks:*"
command: yarn mocha e2e/tests/base-goerli-andromeda/*.e2e.js

workflows:
version: 2.1
Expand Down
49 changes: 49 additions & 0 deletions e2e/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const util = require('util');
const path = require('path');
const { ethers } = require('ethers');

util.inspect.defaultOptions.depth = null;
util.inspect.defaultOptions.maxArrayLength = null;

const fgReset = '\x1b[0m';
const fgRed = '\x1b[31m';
const fgGreen = '\x1b[32m';
const fgYellow = '\x1b[33m';
const fgCyan = '\x1b[36m';

ethers.BigNumber.prototype[util.inspect.custom] = function (depth, inspectOptions, inspect) {
return `${fgCyan}BigNumber( ${fgYellow}${fgGreen}${this.toHexString()} ${fgYellow}${this.toString()}${fgCyan} )${fgReset}`;
};

const [txnsFile] = process.argv.slice(2);
if (!txnsFile) {
console.error(`${fgRed}ERROR: Expected 1 argument${fgReset}`);
console.error(`Usage: ${fgCyan}node e2e/deploy.js "TXNS_FILE"${fgReset}`);
console.error(
`Example: ${fgGreen}node e2e/deploy.js "./upgrade--base-goerli-andromeda.json"${fgReset}`
);
process.exit(1);
}
console.log(`Loading update transactions from ${fgGreen}"${txnsFile}"${fgReset}`);
const upgrade = require(path.resolve(txnsFile));

async function run() {
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
for (const { hash, from, to, data, value } of upgrade.txns) {
// console.log(`provider`, provider);
console.log();
console.log();
console.log();
console.log('============================================================================');
console.log({ hash, from, to, data, value });
await provider.send('anvil_setBalance', [from, ethers.utils.parseEther('10').toHexString()]);
await provider.send('anvil_impersonateAccount', [from]);
const signer = provider.getSigner(from);
const tx = await signer.sendTransaction({ to, data, value });
const result = await tx.wait();
console.log(result);
await provider.send('anvil_stopImpersonatingAccount', [from]);
console.log('============================================================================');
}
}
run();
95 changes: 95 additions & 0 deletions e2e/fetch-local-deployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node

const os = require('os');
const path = require('path');
const fs = require('fs/promises');
const toml = require('@iarna/toml');
const { ethers } = require('ethers');
const { LocalRegistry } = require('@usecannon/cli/dist/src/registry');
const { CliLoader } = require('@usecannon/cli/dist/src/loader');
const CANNON_DIRECTORY = path.join(os.homedir(), '.local', 'share', 'cannon');

const fgReset = '\x1b[0m';
const fgRed = '\x1b[31m';
const fgGreen = '\x1b[32m';
const fgYellow = '\x1b[33m';
const fgCyan = '\x1b[36m';

const [chainId, deploymentFile] = process.argv.slice(2);
if (!chainId || !deploymentFile) {
console.error(`${fgRed}ERROR: Expected 2 arguments${fgReset}`);
console.error(
`Usage: ${fgGreen}node e2e/fetch-local-deployment.js ${fgYellow}chainId ${fgCyan}deploymentFile${fgReset}`
);
console.error(
`Example: ${fgGreen}node e2e/fetch-local-deployment.js ${fgYellow}84531 ${fgCyan}omnibus-base-goerli-andromeda.toml${fgReset}`
);
process.exit(1);
}

function readableAbi(abi) {
return new ethers.utils.Interface(abi).format(ethers.utils.FormatTypes.full);
}

async function run() {
const config = await fs.readFile(deploymentFile, 'utf8');
const { name, version, setting } = toml.parse(config);
const preset = setting?.target_preset?.defaultValue ?? 'main';

console.log('Resolving URL', {
packageRef: `${name}:${version}`,
variant: `${chainId}-${preset}`,
});
const localRegistry = new LocalRegistry(CANNON_DIRECTORY);
const url = await await localRegistry.getUrl(`${name}:${version}`, `${chainId}-${preset}`);
console.log(`Resolved URL:`, { url });

console.log('Fetching deployment state', { url });
const deployments = JSON.parse(
await fs.readFile(`${CANNON_DIRECTORY}/ipfs_cache/${CliLoader.getCacheHash(url)}.json`, 'utf8')
);

await fs.mkdir(`${__dirname}/deployments`, { recursive: true });

const snxAddress = setting?.snx_address?.defaultValue ?? ethers.constants.AddressZero;
await fs.writeFile(
`${__dirname}/deployments/snx.json`,
JSON.stringify({ address: snxAddress }, null, 2)
);

const system = deployments.state['provision.system'].artifacts.imports.system;
await fs.writeFile(
`${__dirname}/deployments/CoreProxy.json`,
JSON.stringify(
{
address: system.contracts.CoreProxy.address,
abi: readableAbi(system.contracts.CoreProxy.abi),
},
null,
2
)
);

async function mintableToken(provisionStep) {
const fakeCollateral =
deployments?.state?.[`provision.${provisionStep}`]?.artifacts?.imports?.[provisionStep];
if (fakeCollateral) {
const [, ticker] = fakeCollateral.contracts.MintableToken.constructorArgs;
await fs.writeFile(
`${__dirname}/deployments/FakeCollateral${ticker}.json`,
JSON.stringify(
{
address: fakeCollateral.contracts.MintableToken.address,
abi: readableAbi(fakeCollateral.contracts.MintableToken.abi),
},
null,
2
)
);
}
}
await mintableToken('usdc_mock_collateral');
await mintableToken('mintableToken');
}

run();
3 changes: 1 addition & 2 deletions e2e/tasks/approveCollateral.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { ethers } = require('ethers');
const { importCoreProxy } = require('./importCoreProxy');
const { getCollateralConfig } = require('./getCollateralConfig');
const CoreProxy = require('../deployments/CoreProxy.json');

const log = require('debug')(`tasks:${require('path').basename(__filename, '.js')}`);

async function approveCollateral({ privateKey, symbol }) {
const CoreProxy = await importCoreProxy();
const config = await getCollateralConfig(symbol);
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const wallet = new ethers.Wallet(privateKey, provider);
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/borrowUsd.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { ethers } = require('ethers');
const { importCoreProxy } = require('./importCoreProxy');
const { getCollateralConfig } = require('./getCollateralConfig');
const CoreProxy = require('../deployments/CoreProxy.json');

const log = require('debug')(`tasks:${require('path').basename(__filename, '.js')}`);

async function borrowUsd({ privateKey, accountId, symbol, amount, poolId }) {
const CoreProxy = await importCoreProxy();
const config = await getCollateralConfig(symbol);
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const wallet = new ethers.Wallet(privateKey, provider);
Expand Down
5 changes: 2 additions & 3 deletions e2e/tasks/createAccount.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { ethers } = require('ethers');
const crypto = require('crypto');
const { importCoreProxy } = require('./importCoreProxy');
// const crypto = require('crypto');
const { getAccountOwner } = require('./getAccountOwner');
const CoreProxy = require('../deployments/CoreProxy.json');

const log = require('debug')(`tasks:${require('path').basename(__filename, '.js')}`);

async function createAccount({ privateKey, accountId }) {
const CoreProxy = await importCoreProxy();
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const wallet = new ethers.Wallet(privateKey, provider);
const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, wallet);
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/delegateCollateral.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { ethers } = require('ethers');
const { getCollateralConfig } = require('./getCollateralConfig');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

const log = require('debug')(`tasks:${require('path').basename(__filename, '.js')}`);

async function delegateCollateral({ privateKey, accountId, symbol, amount, poolId }) {
const CoreProxy = await importCoreProxy();
const config = await getCollateralConfig(symbol);
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const wallet = new ethers.Wallet(privateKey, provider);
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/depositCollateral.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { ethers } = require('ethers');
const { getCollateralConfig } = require('./getCollateralConfig');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

const log = require('debug')(`tasks:${require('path').basename(__filename, '.js')}`);

async function depositCollateral({ privateKey, accountId, symbol, amount }) {
const CoreProxy = await importCoreProxy();
const config = await getCollateralConfig(symbol);
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const wallet = new ethers.Wallet(privateKey, provider);
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/getAccountCollateral.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { ethers } = require('ethers');
const { getCollateralConfig } = require('./getCollateralConfig');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

async function getAccountCollateral({ accountId, symbol }) {
const CoreProxy = await importCoreProxy();
const config = await getCollateralConfig(symbol);
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, provider);
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/getAccountOwner.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { ethers } = require('ethers');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

async function getAccountOwner({ accountId }) {
const CoreProxy = await importCoreProxy();
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, provider);

Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/getCollateralAllowance.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { ethers } = require('ethers');
const { getCollateralConfig } = require('./getCollateralConfig');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

async function getCollateralAllowance({ address, symbol }) {
const CoreProxy = await importCoreProxy();
const config = await getCollateralConfig(symbol);
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const Token = new ethers.Contract(
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/getCollateralConfig.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { ethers } = require('ethers');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

async function getCollateralConfig(symbol) {
const CoreProxy = await importCoreProxy();
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');

const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, provider);
Expand Down
3 changes: 1 addition & 2 deletions e2e/tasks/getConfigUint.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { ethers } = require('ethers');
const { importCoreProxy } = require('./importCoreProxy');
const CoreProxy = require('../deployments/CoreProxy.json');

async function getConfigUint(key) {
const CoreProxy = await importCoreProxy();
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const coreProxy = new ethers.Contract(CoreProxy.address, CoreProxy.abi, provider);
const value = await coreProxy.getConfigUint(ethers.utils.formatBytes32String(key));
Expand Down
4 changes: 1 addition & 3 deletions e2e/tasks/getFakeCollateralTKNBalance.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const { ethers } = require('ethers');
const { importFakeCollateralTKN } = require('./importFakeCollateralTKN');
const FakeCollateralTKN = require('../deployments/FakeCollateralTKN.json');

const log = require('debug')(`tasks:${require('path').basename(__filename, '.js')}`);

async function getFakeCollateralTKNBalance({ address }) {
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const FakeCollateralTKN = await importFakeCollateralTKN();
const erc20 = new ethers.Contract(FakeCollateralTKN.address, FakeCollateralTKN.abi, provider);

const balance = parseFloat(ethers.utils.formatUnits(await erc20.balanceOf(address)));
return balance;
}
Expand Down
17 changes: 0 additions & 17 deletions e2e/tasks/getPreset.js

This file was deleted.

13 changes: 0 additions & 13 deletions e2e/tasks/importCoreProxy.js

This file was deleted.

13 changes: 0 additions & 13 deletions e2e/tasks/importFakeCollateralTKN.js

This file was deleted.

13 changes: 0 additions & 13 deletions e2e/tasks/importSnx.js

This file was deleted.

Loading

0 comments on commit 437b772

Please sign in to comment.