Skip to content

Commit

Permalink
Update github workflow to run tests with ganache
Browse files Browse the repository at this point in the history
  • Loading branch information
abhidtu2014 committed Aug 31, 2023
1 parent eb37e8e commit 6576977
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 39 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ jobs:
run: npm ci
- name: typecheck
run: npm run build
- name: test
run: npm test
- name: Install PM2 and wait-port
run: |
npm install -g pm2
npm install -g wait-port
- name: Run Ganache in the background
working-directory: ./pkg/app
run: |
pm2 --name ganache-service start npm -- run start-ganache
wait-port -t 10000 127.0.0.1:8545
- name: Run tests
run: npm test
- name: Remove ganache process from the background
if: always()
run: |
pm2 delete ganache-service
69 changes: 48 additions & 21 deletions examples/rebalancing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WalletManagerOptions, WalletManagerConfig } from 'wallet-monitor';
import {buildWalletManager} from "../src";
import { WalletManagerOptions, WalletManagerConfig } from "wallet-monitor";
import { buildWalletManager } from "../src";

// npx ganache -i 5777 \
// --wallet.accounts=0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1,200000000000000000 \
Expand All @@ -13,16 +13,15 @@ import {buildWalletManager} from "../src";
// --wallet.accounts=0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3,200000000000000000 \
// --wallet.accounts=0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c,10000000000000000000


const options: WalletManagerOptions = {
logLevel: 'debug',
logLevel: "debug",
balancePollInterval: 5000,
metrics: {
enabled: true,
serve: true,
port: 9091,
},
failOnInvalidChain: true
failOnInvalidChain: true,
};

const allChainWallets: WalletManagerConfig = {
Expand All @@ -32,27 +31,55 @@ const allChainWallets: WalletManagerConfig = {
},
rebalance: {
enabled: true,
strategy: 'pourOver',
strategy: "pourOver",
interval: 10000,
minBalanceThreshold: 0.3,
maxGasPrice: 10000,
gasLimit: 1000000,
},
wallets: [
{ privateKey: '0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1' },
{ privateKey: '0x5da88a1c7df3490d040792fcca4676e709fdd3e6f6e0142accc96cb7e205e1e0' },
{ privateKey: '0xa2c984f6a752ee05af03dac0bb65f3ec93f1498d43d23ebe6c31cf988d771423' },
{ privateKey: '0xe0c1c809d0e80dcaaf200b3aec2a91cd00ed05134f10026113219d89d2f6a9b2' },
{ privateKey: '0x3500084e268b862df23a229f268510cdee92623102c4786b0ade6203fa59f421' },
{ privateKey: '0x49692cfecfb48cee7ce8a14273bda6996b832149ff7260bca09c2ea159e9147f' },
{ privateKey: '0xb2868bd9090dcfbc9d6f3012c98039ee20d778f8ef2d8cb721c56b69578934f3' },
{ privateKey: '0x50156cc51cb7ae4f5e6e2cb14a75fc177a1917fbab1a8675db25619567515ddd' },
{ privateKey: '0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3' },
{ privateKey: '0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c' },
]
{
privateKey:
"0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1",
},
{
privateKey:
"0x5da88a1c7df3490d040792fcca4676e709fdd3e6f6e0142accc96cb7e205e1e0",
},
{
privateKey:
"0xa2c984f6a752ee05af03dac0bb65f3ec93f1498d43d23ebe6c31cf988d771423",
},
{
privateKey:
"0xe0c1c809d0e80dcaaf200b3aec2a91cd00ed05134f10026113219d89d2f6a9b2",
},
{
privateKey:
"0x3500084e268b862df23a229f268510cdee92623102c4786b0ade6203fa59f421",
},
{
privateKey:
"0x49692cfecfb48cee7ce8a14273bda6996b832149ff7260bca09c2ea159e9147f",
},
{
privateKey:
"0xb2868bd9090dcfbc9d6f3012c98039ee20d778f8ef2d8cb721c56b69578934f3",
},
{
privateKey:
"0x50156cc51cb7ae4f5e6e2cb14a75fc177a1917fbab1a8675db25619567515ddd",
},
{
privateKey:
"0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3",
},
{
privateKey:
"0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c",
},
],
},
};

}


export const manager = buildWalletManager({config: allChainWallets, options})
export const manager = buildWalletManager({ config: allChainWallets, options });
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"watch": "tsc -w",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"prettier": "prettier --ignore-path .gitignore --write .",
"test": "jest --silent=false"
"test": "jest --silent=false",
"start-ganache": "npx ganache -i 5777 --wallet.accounts=0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1,200000000000000000 --wallet.accounts=0x5da88a1c7df3490d040792fcca4676e709fdd3e6f6e0142accc96cb7e205e1e0,200000000000000000 --wallet.accounts=0xa2c984f6a752ee05af03dac0bb65f3ec93f1498d43d23ebe6c31cf988d771423,200000000000000000 --wallet.accounts=0xe0c1c809d0e80dcaaf200b3aec2a91cd00ed05134f10026113219d89d2f6a9b2,200000000000000000 --wallet.accounts=0x3500084e268b862df23a229f268510cdee92623102c4786b0ade6203fa59f421,200000000000000000 --wallet.accounts=0x49692cfecfb48cee7ce8a14273bda6996b832149ff7260bca09c2ea159e9147f,200000000000000000 --wallet.accounts=0xb2868bd9090dcfbc9d6f3012c98039ee20d778f8ef2d8cb721c56b69578934f3,200000000000000000 --wallet.accounts=0x50156cc51cb7ae4f5e6e2cb14a75fc177a1917fbab1a8675db25619567515ddd,200000000000000000 --wallet.accounts=0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3,200000000000000000 --wallet.accounts=0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c,10000000000000000000"
},
"repository": {
"type": "git",
Expand Down
18 changes: 18 additions & 0 deletions test/utilities/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { WalletManager } from "../../src/wallet-manager";
import { timeout } from "./common";

export const ETH_ADDR = "0xFa6E597ca1c7E72838c850d1268dDf618D444712";
export const ETH_ADDR_2 = "0x0EaC31cB932229D0Dcc628f89894012b7827481c";

export const checkIfWalletIsReady = async (
walletManager: WalletManager,
): Promise<void> => {
Expand All @@ -12,3 +15,18 @@ export const checkIfWalletIsReady = async (

await timeout<boolean>(isWalletReady, 5000);
};

export const getWallets = () => {
return [
{
address: ETH_ADDR,
privateKey:
"0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1",
},
{
address: ETH_ADDR_2,
privateKey:
"0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c",
},
];
};
22 changes: 7 additions & 15 deletions test/wallet-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import {
WithWalletExecutor,
} from "../src/chain-wallet-manager";
import { ETHEREUM } from "../src/wallets/evm/ethereum.config";
import { checkIfWalletIsReady } from "./utilities/wallet";
import {
ETH_ADDR,
ETH_ADDR_2,
checkIfWalletIsReady,
getWallets,
} from "./utilities/wallet";
import { wait } from "./utilities/common";

const ETH_ADDR = "0xFa6E597ca1c7E72838c850d1268dDf618D444712";
const ETH_ADDR_2 = "0x0EaC31cB932229D0Dcc628f89894012b7827481c";
const WAIT_TO_ACQUIRE_TIMEOUT = 10;

const rebalanceConfig: WalletRebalancingConfig = {
Expand Down Expand Up @@ -142,18 +145,7 @@ const givenAWalletManager = async (
[ETHEREUM]: {
rebalance: rebalanceConfig,
network: DEVNET,
wallets: [
{
address: ETH_ADDR,
privateKey:
"0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1",
},
{
address: ETH_ADDR_2,
privateKey:
"0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c",
},
],
wallets: getWallets(),
},
};

Expand Down

0 comments on commit 6576977

Please sign in to comment.