From 9790009eac41dcd3d8ebaaff3f19f699a2fc3200 Mon Sep 17 00:00:00 2001 From: benedettadavico Date: Tue, 8 Nov 2022 12:30:27 +0100 Subject: [PATCH] WIP --- .github/workflows/validator-api-tests.yml | 32 +++++++++++++++++++ Makefile | 3 ++ .../status/status-mixnode.test.ts | 16 ++++++++-- validator-api/tests/src/endpoints/Status.ts | 15 ++------- 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/validator-api-tests.yml diff --git a/.github/workflows/validator-api-tests.yml b/.github/workflows/validator-api-tests.yml new file mode 100644 index 0000000000..3d8e42846f --- /dev/null +++ b/.github/workflows/validator-api-tests.yml @@ -0,0 +1,32 @@ +name: Tests for validator API + +on: + push: + paths: + - "validator-api/tests/**" + +defaults: + run: + working-directory: validator-api/tests + +jobs: + test: + name: validator api tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Node v18 + uses: actions/setup-node@v3 + with: + node-version: 18.1.0 + + - name: Install yarn + run: yarn install + + - name: Run yarn + run: yarn + + - name: Launch tests + run: yarn test + working-directory: validator-api/tests \ No newline at end of file diff --git a/Makefile b/Makefile index 95d163a7ca..2e2c58f0ee 100644 --- a/Makefile +++ b/Makefile @@ -122,3 +122,6 @@ mixnet-opt: wasm generate-typescript: cd tools/ts-rs-cli && cargo run && cd ../.. yarn types:lint:fix + +run-validator-tests: + cd validator-api/tests/functional_test && yarn test \ No newline at end of file diff --git a/validator-api/tests/functional_test/validator-api/status/status-mixnode.test.ts b/validator-api/tests/functional_test/validator-api/status/status-mixnode.test.ts index 135e3d62c1..3270eb11c5 100644 --- a/validator-api/tests/functional_test/validator-api/status/status-mixnode.test.ts +++ b/validator-api/tests/functional_test/validator-api/status/status-mixnode.test.ts @@ -130,9 +130,10 @@ describe("Get mixnode data", (): void => { expect(typeof response.in_reserve).toBe("string"); }); - it.skip("Post to compute mixnode reward estimation", async ():Promise => { + it("Post to compute mixnode reward estimation", async ():Promise => { const mix_id = config.environmnetConfig.mixnode_identity; - const response = await status.getMixnodeRewardEstimatedComputation(mix_id); + const payload = {"performance": "0.2"} + const response = await status.getMixnodeRewardEstimatedComputation(mix_id, payload); //estimation expect(typeof response.estimation.total_node_reward).toBe("string"); @@ -163,4 +164,15 @@ describe("Get mixnode data", (): void => { expect(typeof response.as_at).toBe("number"); }) + + + it.skip("Post to compute mixnode reward estimation", async ():Promise => { + const mix_id = config.environmnetConfig.mixnode_identity; + const payload = {"performance": "0.7"} + const response = await status.getMixnodeRewardEstimatedComputation(mix_id, payload); + + // TO-DO this test needs calculations to ensure than when passing through different performance values, the reward is also changing as expected + expect(response.estimation.total_node_reward).toContain("986360"); + + }) }); diff --git a/validator-api/tests/src/endpoints/Status.ts b/validator-api/tests/src/endpoints/Status.ts index 643ac1e0fb..bb91bce506 100644 --- a/validator-api/tests/src/endpoints/Status.ts +++ b/validator-api/tests/src/endpoints/Status.ts @@ -86,21 +86,12 @@ export default class Status extends APIClient { } public async getMixnodeRewardEstimatedComputation( - mix_id: number + mix_id: number, + payload: object ): Promise { const response = await this.restClient.sendPost({ route: `/mixnode/${mix_id}/compute-reward-estimation`, - data: { - "performance": "", // TO-DO add a value to this - "active_in_rewarded_set": true, - "pledge_amount": 0, - "total_delegation": 0, // TO-DO grab the values from the mixnode endpoint on explorer-api and use them in this request - "interval_operating_cost": { - "denom": "unym", - "amount": "3000000" - }, - "profit_margin_percent": "" // TO-DO add a value to this - } + data: payload }); return response.data;