-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
6ebd1d1
to
5a92a43
Compare
66fa359
to
ed002c6
Compare
51ed6c1
to
fccc9a0
Compare
There was a problem hiding this 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.
.github/scripts/changePrice.mjs
Outdated
process.exit(1); | ||
} | ||
|
||
const setAtomPrice = async (amount, containerName, agoricNet) => { |
There was a problem hiding this comment.
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
.github/scripts/changePrice.mjs
Outdated
@@ -0,0 +1,35 @@ | |||
import { execa } from 'execa'; |
There was a problem hiding this comment.
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
import { execa } from 'execa'; | |
#! /usr/bin/env node | |
import { execa } from 'execa'; |
.github/scripts/changePrice.mjs
Outdated
const amount = process.env.amount; | ||
const containerName = process.env.containerName; | ||
const agoricNet = process.env.agoricNet; |
There was a problem hiding this comment.
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,
const amount = process.env.amount; | |
const containerName = process.env.containerName; | |
const agoricNet = process.env.agoricNet; | |
const { agoricNet, amount, containerName } = process.env; |
.github/scripts/changePrice.mjs
Outdated
const env = { | ||
AGORIC_NET: agoricNet, | ||
}; |
There was a problem hiding this comment.
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,
const env = { | |
AGORIC_NET: agoricNet, | |
}; | |
const env = { | |
AGORIC_NET, | |
}; |
.github/scripts/checkLiquidation.mjs
Outdated
@@ -0,0 +1,157 @@ | |||
// @ts-check | |||
import fetch from 'node-fetch'; | |||
import assert from 'assert'; |
There was a problem hiding this comment.
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.
import assert from 'assert'; | |
import assert from 'node:assert/strict'; |
.github/scripts/checkLiquidation.mjs
Outdated
@@ -0,0 +1,157 @@ | |||
// @ts-check | |||
import fetch from 'node-fetch'; |
There was a problem hiding this comment.
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.
import fetch from 'node-fetch'; | |
/* eslint-env node */ |
Then below you can use fetch
without import.
.github/scripts/checkLiquidation.mjs
Outdated
expectedIds, | ||
expectedDebts, | ||
expectedBalance, | ||
expectedDenom, |
There was a problem hiding this comment.
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.
.github/scripts/checkLiquidation.mjs
Outdated
// 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]); |
There was a problem hiding this comment.
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,
// 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,
// 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.
.github/workflows/liquidation.yml
Outdated
expectedVaults: 10 | ||
|
||
- name: Place bid for 90IST | ||
run: node .github/scripts/placeBid.mjs |
There was a problem hiding this comment.
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.
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
.
run: node .github/scripts/placeBid.mjs | |
run: ./scripts/placeBid.mjs |
.github/scripts/changePrice.mjs
Outdated
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); | ||
} |
There was a problem hiding this comment.
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:
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 }); |
Thank you for the valuable suggestions. 🙌 I've made the changes. |
7dc8b52
to
0df995d
Compare
There was a problem hiding this 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
👍
This PR introduces a GitHub Actions workflow to automate the testing of liquidation data indexing. The workflow:
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.