Skip to content

Commit

Permalink
test: added integration tests using setParserProvider with TezosToolkit
Browse files Browse the repository at this point in the history
re #660
  • Loading branch information
hui-an-yang committed Oct 25, 2022
1 parent 3280638 commit a82f23a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
55 changes: 54 additions & 1 deletion integration-tests/contract-michelson-origination.spec.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
59 changes: 58 additions & 1 deletion integration-tests/wallet-michelson-origination.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
});
});


})

0 comments on commit a82f23a

Please sign in to comment.