From c898804ad48b9fc73598f0f7ce4af436fe79a0b1 Mon Sep 17 00:00:00 2001 From: Zainen <72581075+zainen@users.noreply.github.com> Date: Fri, 2 Dec 2022 09:34:01 -0800 Subject: [PATCH] add tests for parsing mode for all testnets, and fail case (#2184) * add tests for parsing mode for all testnets, and fail case * one more test fail * format Co-authored-by: Zainen Suzuki --- integration-tests/rpc-taquito.spec.ts | 74 ++++++++++++++++++--------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/integration-tests/rpc-taquito.spec.ts b/integration-tests/rpc-taquito.spec.ts index 61c71a003a..841cb43658 100644 --- a/integration-tests/rpc-taquito.spec.ts +++ b/integration-tests/rpc-taquito.spec.ts @@ -1,33 +1,57 @@ import { CONFIGS } from "./config"; import { RpcClient } from '@taquito/rpc'; +import { HttpResponseError } from "@taquito/http-utils"; -CONFIGS().forEach(({ rpc }) => { - const client = new RpcClient(rpc); +CONFIGS().forEach(({ rpc, knownContract }) => { + const client = new RpcClient(rpc); - describe(`Test Taquito RPC: ${rpc}`, () => { - describe('Test getBlock', () => { - it('Verify that client.getBlock returns a block using default syntax', async (done) => { - // defaults to /chains/main/blocks/head/ - const block = await client.getBlock(); + describe(`Test Taquito RPC: ${rpc}`, () => { + describe('Test getBlock', () => { + it('Verify that client.getBlock returns a block using default syntax', async (done) => { + // defaults to /chains/main/blocks/head/ + const block = await client.getBlock(); - expect(block.protocol).toBeTruthy(); - done(); - }) - it('Verify that client.getBlock({ block: \'head~2\' }) returns a block using head and tilde syntax', async (done) => { - const block = await client.getBlock({ block: 'head~2' }); - const blockHeader = await client.getBlockHeader({ block: block.hash }) + expect(block.protocol).toBeTruthy(); + done(); + }); + it('Verify that client.getBlock({ block: \'head~2\' }) returns a block using head and tilde syntax', async (done) => { + const block = await client.getBlock({ block: 'head~2' }); + const blockHeader = await client.getBlockHeader({ block: block.hash }); - expect(block.header.predecessor).toEqual(blockHeader.predecessor); - done(); - }) - it('Verify that client.getBlock({ block: `${block.hash}~1` }) returns a block using hash and tilde syntax', async (done) => { - const block = await client.getBlock(); - const predecessorBlock = await client.getBlock({ block: `${block.hash}~1` }) + expect(block.header.predecessor).toEqual(blockHeader.predecessor); + done(); + }); + it('Verify that client.getBlock({ block: `${block.hash}~1` }) returns a block using hash and tilde syntax', async (done) => { + const block = await client.getBlock(); + const predecessorBlock = await client.getBlock({ block: `${block.hash}~1` }); - expect(predecessorBlock.hash).toEqual(block.header.predecessor); - done(); - }) - }) - }) -}) + expect(predecessorBlock.hash).toEqual(block.header.predecessor); + done(); + }); + it('Verify that unparse_mode has no error: Readable', async (done) => { + const response = await client.getNormalizedScript(knownContract, { unparsing_mode: 'Readable' }); + expect(response.code).toBeDefined(); + done(); + }); + it('Verify that unparse_mode has no error: Optimized', async (done) => { + const response = await client.getNormalizedScript(knownContract, { unparsing_mode: 'Optimized' }); + expect(response.code).toBeDefined(); + done(); + }); + it('Verify that unparse_mode has no error: Optimized_legacy', async (done) => { + const response = await client.getNormalizedScript(knownContract, { unparsing_mode: 'Optimized_legacy' }); + expect(response.code).toBeDefined(); + done(); + }); + it('Should fail unparsing_mode not acceptable', async (done) => { + expect(() => client.getNormalizedScript(knownContract, { unparsing_mode: 'else' as any })).rejects.toThrowError(HttpResponseError); + done(); + }); + it('Should fail unparsing_mode not acceptable', async (done) => { + expect(() => client.getNormalizedScript(knownContract, {} as any)).rejects.toThrowError(HttpResponseError); + done(); + }); + }); + }); +});