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

automate liquidation testing #36

Merged
merged 10 commits into from
Dec 20, 2024
Merged

Conversation

rabi-siddique
Copy link
Collaborator

@rabi-siddique rabi-siddique commented Dec 17, 2024

This PR introduces a GitHub Actions workflow to automate the testing of liquidation data indexing. The workflow:

  • Launches an A3P container.
  • Sets up the SubQL indexer.
  • Configures three vaults, places three bids, and changes the ATOM price to trigger the liquidation process.

This setup to initiate liquidation is similar to the one in the automated tests in dapp-inter.

After the liquidation process is completed, we make requests to the GraphQL server to retrieve data related to liquidations. We then verify that these data values match our expected values.

@rabi-siddique rabi-siddique changed the base branch from main to rs-test December 17, 2024 09:00
@rabi-siddique rabi-siddique force-pushed the rs-automate-liquidation-testing branch 29 times, most recently from 6ebd1d1 to 5a92a43 Compare December 17, 2024 13:02
@rabi-siddique rabi-siddique force-pushed the rs-automate-liquidation-testing branch 7 times, most recently from 66fa359 to ed002c6 Compare December 18, 2024 13:15
@rabi-siddique rabi-siddique force-pushed the rs-automate-liquidation-testing branch 2 times, most recently from 51ed6c1 to fccc9a0 Compare December 18, 2024 13:37
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on getting this working.

I left some requests that I expect before merging to main but this PR is merging to rs-test so I'll approve that and I'll look for the changes in #35 before approving that for main.

process.exit(1);
}

const setAtomPrice = async (amount, containerName, agoricNet) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function basically is the script. I think it would be best to inline it.

maybe you made it a function because of the await? mjs in Node supports top-level await

i can see a case for calling main() in the last line like you do in the other file, but I think it's best not to parameterize that since the values are coming from env

@@ -0,0 +1,35 @@
import { execa } from 'execa';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a script, please include the shebang so it can be run from shell

Suggested change
import { execa } from 'execa';
#! /usr/bin/env node
import { execa } from 'execa';

Comment on lines 6 to 8
const amount = process.env.amount;
const containerName = process.env.containerName;
const agoricNet = process.env.agoricNet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's surprising to see this different casing for AGORIC_NET but I see how it makes the workflow read better.

though please simplify the expression here with destructuring,

Suggested change
const amount = process.env.amount;
const containerName = process.env.containerName;
const agoricNet = process.env.agoricNet;
const { agoricNet, amount, containerName } = process.env;

Comment on lines 22 to 24
const env = {
AGORIC_NET: agoricNet,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have consistent casing,

Suggested change
const env = {
AGORIC_NET: agoricNet,
};
const env = {
AGORIC_NET,
};

@@ -0,0 +1,157 @@
// @ts-check
import fetch from 'node-fetch';
import assert from 'assert';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you always want strict. just import that version so these read more cleanly.

Suggested change
import assert from 'assert';
import assert from 'node:assert/strict';

@@ -0,0 +1,157 @@
// @ts-check
import fetch from 'node-fetch';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch is global in modern Node.

Suggested change
import fetch from 'node-fetch';
/* eslint-env node */

Then below you can use fetch without import.

Comment on lines 39 to 42
expectedIds,
expectedDebts,
expectedBalance,
expectedDenom,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these parameters aren't really independent of each other. expectedLiquidating and expectedLiquidated have the same structure. please just pass in that object.

Comment on lines 87 to 105
// 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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by importing the strict module above, you don't have to repeat it here,

Suggested change
// 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]);
assert.equal(nodes[0].id, expectedIds[0]);
assert.equal(nodes[1].id, expectedIds[1]);
assert.equal(nodes[2].id, expectedIds[2]);

but these lines are pretty verbose and you have to update them if you change the nodes or expectations. once you've made the change to take a single expectations parameter you can do,

Suggested change
// 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]);
for (const key of Object.keys(expectations) {
for (let i = 0; i < nodes.length; i++) {
assert.equal(nodes[i][key], expecations[i].key);
}
}

Oh though you'll also have to take the plural s off the expectation fixture.

expectedVaults: 10

- name: Place bid for 90IST
run: node .github/scripts/placeBid.mjs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you add the shebang you don't have to specify the interpreter at the callsite. It shouldn't be the concern of the caller how to run it.

Suggested change
run: node .github/scripts/placeBid.mjs
run: .github/scripts/placeBid.mjs

Separately, these scripts have nothing to do with Github. Please put them somewhere else in the repo. e.g. /scripts.

Suggested change
run: node .github/scripts/placeBid.mjs
run: ./scripts/placeBid.mjs

Comment on lines 10 to 16
if (!amount || !containerName || !agoricNet) {
console.error('Error: Missing one or more required parameters:');
if (!amount) console.error('Missing amount');
if (!containerName) console.error('Missing containerName');
if (!agoricNet) console.error('Missing agoricNet');
process.exit(1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this script can import @agoric/internal you could do:

Suggested change
if (!amount || !containerName || !agoricNet) {
console.error('Error: Missing one or more required parameters:');
if (!amount) console.error('Missing amount');
if (!containerName) console.error('Missing containerName');
if (!agoricNet) console.error('Missing agoricNet');
process.exit(1);
}
assertAllDefined({ agoricNet, amount, containerName });

@rabi-siddique
Copy link
Collaborator Author

Thank you for the valuable suggestions. 🙌 I've made the changes.

@rabi-siddique rabi-siddique changed the base branch from rs-test to main December 19, 2024 07:00
@rabi-siddique rabi-siddique changed the base branch from main to rs-test December 19, 2024 07:05
@rabi-siddique rabi-siddique force-pushed the rs-automate-liquidation-testing branch from 7dc8b52 to 0df995d Compare December 19, 2024 07:28
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the changes

👍 :shipit:

@rabi-siddique rabi-siddique merged commit c912d4f into rs-test Dec 20, 2024
2 checks passed
@rabi-siddique rabi-siddique deleted the rs-automate-liquidation-testing branch December 20, 2024 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants