diff --git a/integration-tests/contract-michelson-origination.spec.ts b/integration-tests/contract-michelson-origination.spec.ts index 98799fc734..5abf879bb1 100644 --- a/integration-tests/contract-michelson-origination.spec.ts +++ b/integration-tests/contract-michelson-origination.spec.ts @@ -1,9 +1,62 @@ -import { IntegerError } from "@taquito/taquito"; +import { IntegerError, MichelCodecParser, NoopParser, Context, InvalidCodeParameter } from '@taquito/taquito'; import { CONFIGS } from "./config"; import { idMichelsonCode, idInitData } from "./data/id-contract" CONFIGS().forEach(({ lib, rpc, setup }) => { const Tezos = lib; + + describe(`Test contract origination to configure parserProvider to parse plain Michelson`, () => { + + beforeEach(async (done) => { + await setup() + done() + }) + it('uses noopParser to originate Michelson code and fails', async (done) => { + // Configure the Tezostoolkit to use the NoopParser (the Michelson won't be parsed) + Tezos.setParserProvider(new NoopParser()); + + try { + const op = await Tezos.contract.originate({ + balance: "0", + code: idMichelsonCode, + init: idInitData + }); + await op.confirmation() + } catch (error: any) { + console.log(error.name, error.message) + expect(error).toBeInstanceOf(InvalidCodeParameter); + expect(error.message).toEqual('Wrong code parameter type, expected an array'); + } + done(); + }); + + it('uses MichelCodecParser to originate Michelson code and succeeds', async (done) => { + // Configure the Tezostoolkit to use the MichelCodecParser (the Michelson will be parsed to JSONMichelson) + Tezos.setParserProvider(new MichelCodecParser(new Context(rpc))); + + const op = await Tezos.contract.originate({ + balance: "0", + code: idMichelsonCode, + init: idInitData + }); + await op.confirmation() + expect(op.status).toEqual('applied') + done(); + }); + + it('no parser configures will use MichelCodecParser by default to originate Michelson code and succeeds', async (done) => { + // No parserProvider configured will use MichelCodecParser by dafault (the Michelson will be parsed to JSONMichelson) + const op = await Tezos.contract.originate({ + balance: "0", + code: idMichelsonCode, + init: idInitData + }); + await op.confirmation() + expect(op.status).toEqual('applied') + done(); + }); + }); + describe(`Test contract origination in a plain Michelson through contract api using: ${rpc}`, () => { beforeEach(async (done) => { diff --git a/integration-tests/wallet-michelson-origination.spec.ts b/integration-tests/wallet-michelson-origination.spec.ts index 145c278024..7eab8a00fb 100644 --- a/integration-tests/wallet-michelson-origination.spec.ts +++ b/integration-tests/wallet-michelson-origination.spec.ts @@ -1,5 +1,7 @@ import { CONFIGS } from "./config"; -import { idMichelsonCode, idInitData } from "./data/id-contract" +import { idMichelsonCode, idInitData } from "./data/id-contract"; +import { MichelCodecParser, NoopParser, Context, InvalidCodeParameter } from '@taquito/taquito'; + CONFIGS().forEach(({ lib, rpc, setup }) => { const Tezos = lib; @@ -21,4 +23,59 @@ CONFIGS().forEach(({ lib, rpc, setup }) => { done(); }); }); + + describe(`Test contract origination to configure parserProvider to parse plain Michelson`, () => { + + beforeEach(async (done) => { + await setup() + done() + }) + it('uses noopParser to originate Michelson code and fails', async (done) => { + // Configure the Tezostoolkit to use the NoopParser (the Michelson won't be parsed) + Tezos.setParserProvider(new NoopParser()); + + try { + const op = await Tezos.wallet.originate({ + balance: "0", + code: idMichelsonCode, + init: idInitData + }).send(); + await op.confirmation() + } catch (error: any) { + expect(error).toBeInstanceOf(InvalidCodeParameter); + expect(error.message).toEqual('Wrong code parameter type, expected an array'); + } + done(); + }); + + it('uses MichelCodecParser to originate Michelson code and succeeds', async (done) => { + // Configure the Tezostoolkit to use the MichelCodecParser (the Michelson will be parsed to JSONMichelson) + Tezos.setParserProvider(new MichelCodecParser(new Context(rpc))); + + const op = await Tezos.wallet.originate({ + balance: "0", + code: idMichelsonCode, + init: idInitData + }).send(); + await op.confirmation() + expect(op.opHash).toBeDefined(); + expect(op.status).toBeDefined(); + done(); + }); + + it('no parser configures will use MichelCodecParser by default to originate Michelson code and succeeds', async (done) => { + // No parserProvider configured will use MichelCodecParser by dafault (the Michelson will be parsed to JSONMichelson) + const op = await Tezos.wallet.originate({ + balance: "0", + code: idMichelsonCode, + init: idInitData + }).send(); + await op.confirmation() + expect(op.opHash).toBeDefined(); + expect(op.status).toBeDefined(); + done(); + }); + }); + + })