Skip to content

Commit

Permalink
ci: validate liquidating vaults
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Dec 18, 2024
1 parent 05619b3 commit fccc9a0
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .github/scripts/changePrice.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ const setAtomPrice = async (amount, containerName, agoricNet) => {
};

const command = `${agops} oracle setPrice --keys gov1,gov2 --pair ATOM.USD --price ${amount} --keyring-backend=test`;
const { stdout, stderr } = await execa('docker', ['exec', containerName, command], { env, shell: true });
const { stdout } = await execa('docker', ['exec', containerName, command], { env, shell: true });

assert.strictEqual(stderr, '', `Expected stderr to be empty, but received: '${stderr}'`);
console.log('Standard output:', stdout);
} catch (error) {
console.error('Error:', error);
Expand Down
157 changes: 157 additions & 0 deletions .github/scripts/checkLiquidation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// @ts-check
import fetch from 'node-fetch';
import assert from 'assert';
const delay = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

const states = {
liquidated: 'liquidated',
liquidating: 'liquidating',
};

const expectedLiquidating = {
ids: [
'published.vaultFactory.managers.manager0.vaults.vault10-liquidating',
'published.vaultFactory.managers.manager0.vaults.vault11-liquidating',
'published.vaultFactory.managers.manager0.vaults.vault12-liquidating',
],
debts: ['100500000', '103515000', '105525000'],
balance: ['15000000', '15000000', '15000000'],
denom: 'ATOM',
};

const expectedLiquidated = {
ids: [
'published.vaultFactory.managers.manager0.vaults.vault10-liquidated',
'published.vaultFactory.managers.manager0.vaults.vault11-liquidated',
'published.vaultFactory.managers.manager0.vaults.vault12-liquidated',
],
debts: ['0', '0', '0'],
balance: ['3425146', '3077900', '2846403'],
denom: 'ATOM',
};

const validate = async ({
apiUrl,
maxRetries,
retryDuration,
expectedIds,
expectedDebts,
expectedBalance,
expectedDenom,
filterState,
}) => {
console.log(`Checking ${filterState} vaults...`);
let retries = 0;

while (retries < maxRetries) {
try {
const graphqlQuery = {
query: `query {
vaultLiquidations (filter: {state: {equalTo: "${filterState}"}}) {
nodes {
id
denom
debt
state
balance
}
}
}`,
};

const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify(graphqlQuery),
});

const jsonResponse = await response.json();
console.log('Response:', JSON.stringify(jsonResponse));

const nodes = jsonResponse?.data?.vaultLiquidations?.nodes || [];
if (nodes.length !== 3) {
console.error(`Attempt ${retries + 1}: No data available`);
retries++;
await delay(retryDuration);
continue;
}

nodes.sort((a, b) => a.id.localeCompare(b.id));
console.log('Sorted Nodes:', JSON.stringify(nodes));

// Validate Ids
assert.strictEqual(nodes[0].id, expectedIds[0]);
assert.strictEqual(nodes[1].id, expectedIds[1]);
assert.strictEqual(nodes[2].id, expectedIds[2]);

// Validate Debts
assert.strictEqual(nodes[0].debt, expectedDebts[0]);
assert.strictEqual(nodes[1].debt, expectedDebts[1]);
assert.strictEqual(nodes[2].debt, expectedDebts[2]);

// Validate Denom
assert.strictEqual(nodes[0].denom, expectedDenom);
assert.strictEqual(nodes[1].denom, expectedDenom);
assert.strictEqual(nodes[2].denom, expectedDenom);

// Validate Balance
assert.strictEqual(nodes[0].balance, expectedBalance[0]);
assert.strictEqual(nodes[1].balance, expectedBalance[1]);
assert.strictEqual(nodes[2].balance, expectedBalance[2]);

console.log('All validations passed successfully.');
return;
} catch (error) {
console.error(`Error on attempt ${retries + 1} fetching active vaults:`, error);
retries++;
await delay(retryDuration);
}
}

console.error('Maximum retry attempts reached. Exiting...');
process.exit(1);
};

const main = async () => {
console.log('Starting main process...');

const apiUrl = process.env.API_URL || 'http://localhost:3000/';
console.log(`API URL set to: ${apiUrl}`);

try {
console.log('Validating liquidating vaults...');
await validate({
apiUrl,
expectedIds: expectedLiquidating.ids,
expectedBalance: expectedLiquidating.balance,
expectedDenom: expectedLiquidating.denom,
expectedDebts: expectedLiquidating.debts,
maxRetries: 6,
retryDuration: 3 * 60 * 1000,
filterState: states.liquidating,
});
console.log('Validation successful for liquidating vaults.');

console.log('Validating liquidated vaults...');
await validate({
apiUrl,
expectedIds: expectedLiquidated.ids,
expectedBalance: expectedLiquidated.balance,
expectedDenom: expectedLiquidated.denom,
expectedDebts: expectedLiquidated.debts,
maxRetries: 3,
retryDuration: 2 * 60 * 1000,
filterState: states.liquidated,
});
console.log('Validation successful for liquidated vaults.');
} catch (error) {
console.error('Validation failed:', error);
}
};

main();
13 changes: 12 additions & 1 deletion .github/workflows/liquidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: node .github/scripts/getActiveVaults.mjs
env:
apiUrl: 'http://localhost:3000/'
expectedVaults: '7'
expectedVaults: 7

- name: Create Vault with 100 Minted and 15 Collateral
run: node .github/scripts/createVault.mjs
Expand Down Expand Up @@ -122,3 +122,14 @@ jobs:
amount: 9.99
containerName: agd
agoricNet: local

- name: Check liquidation indexing
run: node .github/scripts/checkLiquidation.mjs
env:
apiUrl: 'http://localhost:3000/'

- name: Get active vaults
run: node .github/scripts/getActiveVaults.mjs
env:
apiUrl: 'http://localhost:3000/'
expectedVaults: 7
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
services:
a3p:
image: ghcr.io/agoric/agoric-3-proposals@sha256:644e09bf041e5588570ff9a49e6129cc468e9c8458417541027e8532cb91083b
image: ghcr.io/agoric/agoric-3-proposals:use-upgrade-17
ports:
- 26657:26657
postgres:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"@cosmjs/stargate": "^0.28.9",
"@subql/cli": "^5.4.0",
"@subql/node-cosmos": "4.2.1",
"@subql/node-cosmos": "^4.2.1",
"@subql/testing": "latest",
"execa": "^9.5.2",
"prettier": "^3.4.2",
Expand Down
44 changes: 14 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3228,9 +3228,9 @@ __metadata:
languageName: node
linkType: hard

"@subql/common-cosmos@npm:5.0.6":
version: 5.0.6
resolution: "@subql/common-cosmos@npm:5.0.6"
"@subql/common-cosmos@npm:5.1.0":
version: 5.1.0
resolution: "@subql/common-cosmos@npm:5.1.0"
dependencies:
"@cosmwasm/ts-codegen": "npm:^1.11.1"
"@protobufs/cosmos": "npm:^0.1.0"
Expand All @@ -3240,7 +3240,7 @@ __metadata:
"@protobufs/google": "npm:^0.0.10"
"@protobufs/ibc": "npm:^0.1.0"
"@protobufs/tendermint": "npm:^0.0.10"
"@subql/common": "npm:^5.2.1"
"@subql/common": "npm:^5.2.2"
"@subql/types-cosmos": "npm:4.0.0"
"@subql/x-cosmology-telescope": "npm:^1.4.14"
fs-extra: "npm:^11.1.1"
Expand All @@ -3250,11 +3250,11 @@ __metadata:
class-transformer: "*"
class-validator: "*"
ejs: "*"
checksum: 10c0/7c1b2beb1d0497d1aa4bbf987c2bd91ccbe4f13456259dcdd9dc6fae10e791e7efdf6e01061ce35e1e219dd41429fb639595053574b75f301d911061af268ca1
checksum: 10c0/83f6eabcdf6dcf2d9d8e499201f7751eb2009ec0c501be2c58b0e269ee40d77d34db90090562afbf91ff10bf9adaec9e04aff025766829200c95f035eff58c4b
languageName: node
linkType: hard

"@subql/common@npm:5.2.2":
"@subql/common@npm:5.2.2, @subql/common@npm:^5.2.2":
version: 5.2.2
resolution: "@subql/common@npm:5.2.2"
dependencies:
Expand All @@ -3271,22 +3271,6 @@ __metadata:
languageName: node
linkType: hard

"@subql/common@npm:^5.2.1":
version: 5.2.1
resolution: "@subql/common@npm:5.2.1"
dependencies:
"@subql/types-core": "npm:2.0.0"
axios: "npm:^0.28.0"
class-transformer: "npm:^0.5.1"
class-validator: "npm:^0.14.1"
js-yaml: "npm:^4.1.0"
reflect-metadata: "npm:^0.1.14"
semver: "npm:^7.6.3"
update-notifier: "npm:^5.1.0"
checksum: 10c0/02ac5e46489e9eeb73f01c007e868d491f415462d654149bb296f1c4f0d74ff67b4881458a154f237a1e88df7f4a99fdf0ff44739b85ae44b871234642753fc6
languageName: node
linkType: hard

"@subql/node-core@npm:^16.1.0":
version: 16.1.0
resolution: "@subql/node-core@npm:16.1.0"
Expand Down Expand Up @@ -3319,9 +3303,9 @@ __metadata:
languageName: node
linkType: hard

"@subql/node-cosmos@npm:4.2.1":
version: 4.2.1
resolution: "@subql/node-cosmos@npm:4.2.1"
"@subql/node-cosmos@npm:^4.2.1":
version: 4.3.0
resolution: "@subql/node-cosmos@npm:4.3.0"
dependencies:
"@cosmjs/cosmwasm-stargate": "npm:^0.32.4"
"@cosmjs/proto-signing": "npm:^0.32.4"
Expand All @@ -3333,9 +3317,9 @@ __metadata:
"@nestjs/event-emitter": "npm:^2.0.0"
"@nestjs/platform-express": "npm:^9.4.0"
"@nestjs/schedule": "npm:^3.0.1"
"@subql/common": "npm:^5.2.1"
"@subql/common-cosmos": "npm:5.0.6"
"@subql/node-core": "npm:^15.0.2"
"@subql/common": "npm:^5.2.2"
"@subql/common-cosmos": "npm:5.1.0"
"@subql/node-core": "npm:^16.1.0"
"@subql/types-cosmos": "npm:4.0.0"
lodash: "npm:^4.17.21"
protobufjs: "npm:^6.11.4"
Expand All @@ -3346,7 +3330,7 @@ __metadata:
"@subql/utils": "*"
bin:
subql-node-cosmos: ./bin/run
checksum: 10c0/950dc4aae8bbca6b47c8e618c44d2d7c63ea39206d748f3a4d57a105e88509447fa72c0f6d6fd92b0394aec030f1f9cf932715d864e031cf0ebe49adbf4dcd74
checksum: 10c0/78cc7dbde1cb39465ec3d1f231105a69e33cd7eb98bcb06d8aa45264ee9eb3b64777147ead5d6d6b9ab92bcfed73dff6344fbb8b23233dc7fda0d5f2885d124a
languageName: node
linkType: hard

Expand Down Expand Up @@ -4121,7 +4105,7 @@ __metadata:
dependencies:
"@cosmjs/stargate": "npm:^0.28.9"
"@subql/cli": "npm:^5.4.0"
"@subql/node-cosmos": "npm:4.2.1"
"@subql/node-cosmos": "npm:^4.2.1"
"@subql/testing": "npm:latest"
"@subql/types-cosmos": "npm:^4.0.0"
"@subql/utils": "npm:^2.17.0"
Expand Down

0 comments on commit fccc9a0

Please sign in to comment.