diff --git a/packages/taquito-michelson-encoder/test/baker_registry.spec.ts b/packages/taquito-michelson-encoder/test/baker_registry.spec.ts index d89ac8d0e8..91c974d82a 100644 --- a/packages/taquito-michelson-encoder/test/baker_registry.spec.ts +++ b/packages/taquito-michelson-encoder/test/baker_registry.spec.ts @@ -8,9 +8,9 @@ describe('Baker Registry contract test', () => { const schema = new Schema(storage); expect(schema.ExtractSchema()).toEqual({ '0': { - big_map : { + big_map: { key: "key_hash", - value : { + value: { data: 'bytes', last_update: 'timestamp', reporter: 'address', @@ -21,6 +21,56 @@ describe('Baker Registry contract test', () => { signup_fee: 'mutez', update_fee: 'mutez', }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: "key_hash", + schema: "key_hash" + }, + value: { + __michelsonType: "pair", + schema: { + data: { + __michelsonType: "option", + schema: { + __michelsonType: 'bytes', + schema: "bytes" + } + }, + last_update: { + __michelsonType: 'timestamp', + schema: "timestamp" + }, + reporter: { + __michelsonType: "option", + schema: { + __michelsonType: 'address', + schema: "address" + } + }, + } + }, + }, + }, + owner: { + __michelsonType: 'address', + schema: "address" + }, + signup_fee: { + __michelsonType: 'mutez', + schema: "mutez" + }, + update_fee: { + __michelsonType: 'mutez', + schema: "mutez" + }, + } + }); }); it('Decode storage properly', () => { @@ -70,6 +120,58 @@ describe('Baker Registry contract test', () => { withdraw: 'contract', }); + console.log(JSON.stringify(schema.generateSchema(), null, 2)) + expect(schema.generateSchema()).toEqual({ + __michelsonType: "or", + schema: { + set_data: { + __michelsonType: "pair", + schema: { + delegate: { + __michelsonType: "key_hash", + schema: 'key_hash' + }, + data: { + __michelsonType: "option", + schema: { + __michelsonType: "bytes", + schema: 'bytes' + } + }, + reporter: { + __michelsonType: "option", + schema: { + __michelsonType: "address", + schema: 'address' + } + }, + } + }, + set_fees: { + __michelsonType: "pair", + schema: { + signup_fee: { + __michelsonType: "mutez", + schema: 'mutez' + }, + update_fee: { + __michelsonType: "mutez", + schema: 'mutez' + }, + } + }, + withdraw: { + __michelsonType: "contract", + schema: { + parameter: { + __michelsonType: "unit", + schema: "unit" + } + } + }, + } + }); + expect(schema.ExtractSignatures()).toContainEqual(['set_data', 'key_hash', 'bytes', 'address']); expect(schema.ExtractSignatures()).toContainEqual(['set_fees', 'mutez', 'mutez']); expect(schema.ExtractSignatures()).toContainEqual(['withdraw', 'contract']); diff --git a/packages/taquito-michelson-encoder/test/manager.spec.ts b/packages/taquito-michelson-encoder/test/manager.spec.ts index b93d969458..7489b0195c 100644 --- a/packages/taquito-michelson-encoder/test/manager.spec.ts +++ b/packages/taquito-michelson-encoder/test/manager.spec.ts @@ -6,6 +6,10 @@ describe('Schema test', () => { it('Should parse storage schema properly', () => { const schema = new Schema(storage); expect(schema.ExtractSchema()).toEqual('key_hash'); + expect(schema.generateSchema()).toEqual({ + __michelsonType: "key_hash", + schema:'key_hash' + }); }); it('Should parse storage properly', () => { diff --git a/packages/taquito-michelson-encoder/test/proto005/token_contract_with_bigmap.spec.ts b/packages/taquito-michelson-encoder/test/proto005/token_contract_with_bigmap.spec.ts index 346a06e9b9..2796f4162c 100644 --- a/packages/taquito-michelson-encoder/test/proto005/token_contract_with_bigmap.spec.ts +++ b/packages/taquito-michelson-encoder/test/proto005/token_contract_with_bigmap.spec.ts @@ -30,6 +30,55 @@ describe('Token contract with big map', () => { '2': 'bool', '3': 'nat', }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + '0': { + __michelsonType: 'big_map', + schema: { + key: { + __michelsonType: 'address', + schema: 'address' + }, + value: { + __michelsonType: 'pair', + schema: { + '0': { + __michelsonType: 'nat', + schema: 'nat' + }, + '1': { + __michelsonType: 'map', + schema: { + key: { + __michelsonType: 'address', + schema: 'address' + }, + value: { + __michelsonType: 'nat', + schema: 'nat' + }, + }, + }, + } + }, + }, + }, + '1': { + __michelsonType: 'address', + schema: 'address' + }, + '2': { + __michelsonType: 'bool', + schema: 'bool' + }, + '3': { + __michelsonType: 'nat', + schema: 'nat' + }, + } + }); }); it('should encode a big map key properly', () => { diff --git a/packages/taquito-michelson-encoder/test/sample1.spec.ts b/packages/taquito-michelson-encoder/test/sample1.spec.ts index 21204d7f8b..2ab346d56c 100644 --- a/packages/taquito-michelson-encoder/test/sample1.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample1.spec.ts @@ -20,8 +20,8 @@ describe('Schema test', () => { value: 'nat', }, }, - balance: 'nat', - }, + balance: 'nat', + }, }, }, name: 'string', @@ -30,6 +30,63 @@ describe('Schema test', () => { totalSupply: 'nat', version: 'nat', }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "pair", + schema: { + accounts: { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: "pair", + schema: { + allowances: { + __michelsonType: "map", + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: "nat", + schema: "nat" + }, + }, + }, + balance: { + __michelsonType: "nat", + schema: "nat" + } + } + }, + }, + }, + name: { + __michelsonType: "string", + schema: "string" + }, + owner: { + __michelsonType: "address", + schema: "address" + }, + symbol: { + __michelsonType: "string", + schema: "string" + }, + totalSupply: { + __michelsonType: "nat", + schema: "nat" + }, + version: { + __michelsonType: "nat", + schema: "nat" + }, + } + }); }); it('Should encode storage properly', () => { @@ -164,7 +221,7 @@ describe('Schema test', () => { '5': 'address', '6': 'nat', }, - createAccounts: { + createAccounts: { list: { "6": "address", "7": "nat", @@ -180,6 +237,133 @@ describe('Schema test', () => { '4': 'nat', }, }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "or", + schema: { + allowance: { + __michelsonType: "pair", + schema: { + '4': { + __michelsonType: "address", + schema: "address" + }, + '5': { + __michelsonType: "address", + schema: "address" + }, + NatNatContract: { + __michelsonType: "contract", + schema: { + parameter: { + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: "nat", + schema: "nat" + }, + '1': { + __michelsonType: "nat", + schema: "nat" + } + } + } + } + } + } + }, + approve: { + __michelsonType: "pair", + schema: { + '1': { + __michelsonType: "address", + schema: "address" + }, + '2': { + __michelsonType: "nat", + schema: "nat" + } + } + }, + balanceOf: { + __michelsonType: "pair", + schema: { + '3': { + __michelsonType: "address", + schema: "address" + }, + NatContract: { + __michelsonType: "contract", + schema: { + parameter: { + __michelsonType: "nat", + schema: "nat" + } + } + }, + } + }, + createAccount: { + __michelsonType: "pair", + schema: { + '5': { + __michelsonType: "address", + schema: "address" + }, + '6': { + __michelsonType: "nat", + schema: "nat" + }, + } + }, + createAccounts: { + __michelsonType: "list", + schema: { + __michelsonType: "pair", + schema: { + "6": { + __michelsonType: "address", + schema: "address" + }, + "7": { + __michelsonType: "nat", + schema: "nat" + }, + } + }, + }, + transfer: { + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: "address", + schema: "address" + }, + '1': { + __michelsonType: "nat", + schema: "nat" + }, + } + }, + transferFrom: { + __michelsonType: "pair", + schema: { + '2': { + __michelsonType: "address", + schema: "address" + }, + '3': { + __michelsonType: "address", + schema: "address" + }, + '4': { + __michelsonType: "nat", + schema: "nat" + }, + } + }, + } + }); }); it('Should extract signature properly', () => { @@ -190,12 +374,12 @@ describe('Schema test', () => { expect(sig).toContainEqual(['balanceOf', 'address', 'contract']); expect(sig).toContainEqual(['createAccount', 'address', 'nat']); expect(sig).toContainEqual(["createAccounts", { - list: { - "6": "address", - "7": "nat" - } - } - ]); + list: { + "6": "address", + "7": "nat" + } + } + ]); expect(sig).toContainEqual(['transfer', 'address', 'nat']); expect(sig).toContainEqual(['transferFrom', 'address', 'address', 'nat']); }); @@ -217,5 +401,5 @@ describe('Schema test', () => { const valueFound = storageSchema.FindFirstInTopLevelPair(rpcContractResponse.script.storage, typeOfValueToFind); expect(valueFound).toEqual({ string: 'Token B' }); }); - + }); diff --git a/packages/taquito-michelson-encoder/test/sample11_dexter.spec.ts b/packages/taquito-michelson-encoder/test/sample11_dexter.spec.ts index 77e72effa7..11ef24ee48 100644 --- a/packages/taquito-michelson-encoder/test/sample11_dexter.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample11_dexter.spec.ts @@ -13,7 +13,7 @@ describe('Exchange contract test', () => { it('Test storage schema', () => { const schema = new Schema(storageDexter); expect(schema.ExtractSchema()).toEqual({ - '0': { + '0': { big_map: { key: "address", value: "nat" @@ -50,6 +50,196 @@ describe('Exchange contract test', () => { }, }, }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + '0': { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: "nat", + schema: "nat" + } + } + }, + '1': { + __michelsonType: 'contract', + schema: { + parameter: { + __michelsonType: 'or', + schema: { + 0: { + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'address', + schema: 'address' + }, + 1: { + __michelsonType: 'contract', + schema: { + parameter: { + __michelsonType: 'or', + schema: { + 0: { + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'address', + schema: 'address' + }, + 1: { + __michelsonType: 'address', + schema: 'address' + }, + 2: { + __michelsonType: 'nat', + schema: 'nat' + }, + } + }, + 1: { + __michelsonType: 'address', + schema: 'address' + } + } + } + } + } + } + }, + 1: { + __michelsonType: 'nat', + schema: 'nat' + } + } + } + } + }, + '2': { + __michelsonType: 'contract', + schema: { + parameter: { + __michelsonType: "or", + schema: { + 0: { + __michelsonType: "pair", + schema: { + 0: { + __michelsonType: 'address', + schema: 'address' + }, + 1: { + __michelsonType: 'address', + schema: 'address' + }, + 2: { + __michelsonType: 'nat', + schema: 'nat' + }, + } + }, + 1: { + __michelsonType: 'address', + schema: 'address' + } + } + } + } + }, + '3': { + __michelsonType: 'nat', + schema: 'nat' + }, + '4': { + __michelsonType: "map", + schema: { + key: { + __michelsonType: 'address', + schema: 'address' + }, + value: { + __michelsonType: "or", + schema: { + '0': { + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: 'nat', + schema: 'nat' + }, + '1': { + __michelsonType: 'nat', + schema: 'nat' + }, + '2': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '1': { + __michelsonType: 'pair', + schema: { + '1': { + __michelsonType: 'nat', + schema: 'nat' + }, + '2': { + __michelsonType: 'mutez', + schema: 'mutez' + }, + '3': { + __michelsonType: 'nat', + schema: 'nat' + }, + '4': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '2': { + __michelsonType: 'pair', + schema: { + '2': { + __michelsonType: 'nat', + schema: 'nat' + }, + '3': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '3': { + __michelsonType: 'pair', + schema: { + '3': { + __michelsonType: 'nat', + schema: 'nat' + }, + '4': { + __michelsonType: 'mutez', + schema: 'mutez' + }, + '5': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + } + }, + }, + }, + } + }); }); it('Test storage parsing', () => { @@ -104,6 +294,84 @@ describe('Exchange contract test', () => { }, '4': 'nat', }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "or", + schema: { + '0': { + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: 'nat', + schema: 'nat' + }, + '1': { + __michelsonType: 'nat', + schema: 'nat' + }, + '2': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '1': { + __michelsonType: "pair", + schema: { + '1': { + __michelsonType: 'nat', + schema: 'nat' + }, + '2': { + __michelsonType: 'mutez', + schema: 'mutez' + }, + '3': { + __michelsonType: 'nat', + schema: 'nat' + }, + '4': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '2': { + __michelsonType: "pair", + schema: { + '2': { + __michelsonType: 'nat', + schema: 'nat' + }, + '3': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '3': { + __michelsonType: "pair", + schema: { + '3': { + __michelsonType: 'nat', + schema: 'nat' + }, + '4': { + __michelsonType: 'mutez', + schema: 'mutez' + }, + '5': { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + } + }, + '4': { + __michelsonType: 'nat', + schema: 'nat' + }, + } + }); }); it('Encode parameter properly func 0', () => { @@ -273,6 +541,55 @@ describe('Exchange contract test', () => { '2': 'string', '3': 'string', }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: 'pair', + schema: { + '0': { + __michelsonType: "nat", + schema: "nat" + }, + '1': { + __michelsonType: 'map', + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: "nat", + schema: "nat" + }, + }, + }, + } + }, + }, + }, + '1': { + __michelsonType: "nat", + schema: "nat" + }, + '2': { + __michelsonType: "string", + schema: "string" + }, + '3': { + __michelsonType: "string", + schema: "string" + }, + } + }); }); it('Test storage parsing', () => { @@ -296,6 +613,33 @@ describe('Exchange contract test', () => { '1': 'address', }); + expect(schema.generateSchema()).toEqual({ + __michelsonType: "or", + schema: { + '0': { + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: 'address', + schema: "address" + }, + '1': { + __michelsonType: 'address', + schema: "address" + }, + '2': { + __michelsonType: 'nat', + schema: "nat" + }, + } + }, + '1': { + __michelsonType: 'address', + schema: "address" + }, + } + }); + expect(schema.ExtractSignatures()).toContainEqual(['1', 'address']); expect(schema.ExtractSignatures()).toContainEqual(['0', 'address', 'address', 'nat']); }); diff --git a/packages/taquito-michelson-encoder/test/sample13_map_contract.spec.ts b/packages/taquito-michelson-encoder/test/sample13_map_contract.spec.ts index 6f63a0c523..307b3f54e5 100644 --- a/packages/taquito-michelson-encoder/test/sample13_map_contract.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample13_map_contract.spec.ts @@ -20,5 +20,19 @@ describe('Schema with a map as root storage', () => { value: 'string', }, }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "map", + schema: { + key: { + __michelsonType: "nat", + schema: 'nat' + }, + value: { + __michelsonType: "string", + schema: 'string' + } + }, + }); }); }); diff --git a/packages/taquito-michelson-encoder/test/sample18_nat_ticket.spec.ts b/packages/taquito-michelson-encoder/test/sample18_nat_ticket.spec.ts index ca4fba89bb..8662b83698 100644 --- a/packages/taquito-michelson-encoder/test/sample18_nat_ticket.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample18_nat_ticket.spec.ts @@ -44,6 +44,77 @@ describe('Schema with a ticket of type nat inside a big map %tickets in storage' } } }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + admin: { + __michelsonType: 'address', + schema: 'address' + }, + current_id: { + __michelsonType: 'nat', + schema: 'nat' + }, + tickets: { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: 'nat', + schema: 'nat' + }, + value: { + __michelsonType: "ticket", + schema: { + amount: { + __michelsonType: 'int', + schema: 'int' + }, + ticketer: { + __michelsonType: 'contract', + schema: 'contract' + }, + value: { + __michelsonType: 'nat', + schema: 'nat' + } + } + } + } + }, + token_metadata: { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: 'nat', + schema: 'nat' + }, + value: { + __michelsonType: 'pair', + schema: { + '0': { + __michelsonType: 'nat', + schema: 'nat' + }, + '1': { + __michelsonType: 'map', + schema: { + key: { + __michelsonType: 'string', + schema: 'string' + }, + value: { + __michelsonType: 'bytes', + schema: 'bytes' + } + } + } + } + }, + } + } + } + }); }); it('Should parse big map value properly', () => { @@ -51,7 +122,7 @@ describe('Schema with a ticket of type nat inside a big map %tickets in storage' prim: 'big_map', args: [{ prim: 'nat' }, { prim: 'ticket', args: [{ prim: 'nat' }] }], annots: ['%tickets'] - }); + }); const value = schema.ExecuteOnBigMapValue(bigMapValue); expect(value).toEqual({ ticketer: 'KT1EAMUQC1yJ2sRPNPpLHVMGCzroYGe1C1ea', diff --git a/packages/taquito-michelson-encoder/test/sample19_timestamp_ticket.spec.ts b/packages/taquito-michelson-encoder/test/sample19_timestamp_ticket.spec.ts index cee5d83159..021caed201 100644 --- a/packages/taquito-michelson-encoder/test/sample19_timestamp_ticket.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample19_timestamp_ticket.spec.ts @@ -35,10 +35,10 @@ describe('Schema with a ticket of type timestamp inside a big map %tickets in st const schema = new Schema(storage); expect(schema.ExtractSchema()).toEqual({ data: { - winners: { + winners: { big_map: { key: "address", - value: "mutez" + value: "mutez" } }, bets: { @@ -74,6 +74,129 @@ describe('Schema with a ticket of type timestamp inside a big map %tickets in st }, } }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + data: { + __michelsonType: 'pair', + schema: { + winners: { + __michelsonType: "big_map", + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: "mutez", + schema: "mutez" + } + } + }, + bets: { + __michelsonType: 'map', + schema: { + key: { + __michelsonType: "address", + schema: "address" + }, + value: { + __michelsonType: "nat", + schema: "nat" + } + } + }, + current_pot: { + __michelsonType: "mutez", + schema: "mutez" + }, + opened_at: { + __michelsonType: "timestamp", + schema: "timestamp" + }, + settings: { + __michelsonType: 'pair', + schema: { + pool_type: { + __michelsonType: "string", + schema: "string" + }, + entrance_fee: { + __michelsonType: "mutez", + schema: "mutez" + }, + minimum_bet: { + __michelsonType: "mutez", + schema: "mutez" + }, + open_period: { + __michelsonType: "int", + schema: "int" + }, + validation_delay: { + __michelsonType: "int", + schema: "int" + }, + ticket_validity: { + __michelsonType: "int", + schema: "int" + }, + max_capacity: { + __michelsonType: "nat", + schema: "nat" + } + } + }, + validator: { + __michelsonType: 'option', + schema: { + __michelsonType: 'address', + schema: "address" + } + }, + pending_validation: { + __michelsonType: 'bool', + schema: "bool" + }, + oracle: { + __michelsonType: 'address', + schema: "address" + }, + admin: { + __michelsonType: 'address', + schema: "address" + } + } + }, + tickets: { + __michelsonType: 'big_map', + schema: { + key: { + __michelsonType: 'address', + schema: "address" + }, + value: { + __michelsonType: 'ticket', + schema: { + amount: { + __michelsonType: 'int', + schema: "int" + }, + ticketer: { + __michelsonType: 'contract', + schema: "contract" + }, + value: { + __michelsonType: 'timestamp', + schema: "timestamp" + } + } + }, + }, + } + } + }); }); it('Should parse big map value properly', () => { diff --git a/packages/taquito-michelson-encoder/test/sample20.spec.ts b/packages/taquito-michelson-encoder/test/sample20.spec.ts index d872253b72..2b0dc79664 100644 --- a/packages/taquito-michelson-encoder/test/sample20.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample20.spec.ts @@ -55,6 +55,135 @@ describe('Contract test where the value of the map "selling" is a big_map', () = }, tokenAddress: 'address', }); + + expect(schema.generateSchema()).toEqual({ + "__michelsonType": "pair", + schema: { + _euranov: { + "__michelsonType": "address", + "schema": "address" + }, + admin: { + "__michelsonType": "address", + "schema": "address" + }, + auctions: { + "__michelsonType": "big_map", + "schema": { + key: { + "__michelsonType": "address", + "schema": "address" + }, + value: { + __michelsonType: 'map', + schema: { + key: { + "__michelsonType": "nat", + "schema": "nat" + }, + value: { + "__michelsonType": "pair", + "schema": { + assetId: { + "__michelsonType": "nat", + "schema": "nat" + }, + bidCount: { + "__michelsonType": "nat", + "schema": "nat" + }, + claimed: { + "__michelsonType": "bool", + "schema": "bool" + }, + creator: { + "__michelsonType": "address", + "schema": "address" + }, + currentBidAmount: { + "__michelsonType": "mutez", + "schema": "mutez" + }, + currentBidOwner: { + "__michelsonType": "address", + "schema": "address" + }, + duration: { + "__michelsonType": "int", + "schema": "int" + }, + startTime: { + "__michelsonType": "timestamp", + "schema": "timestamp" + }, + } + }, + }, + }, + } + }, + authorizedSC: { + "__michelsonType": "big_map", + "schema": { + key: { + "__michelsonType": "address", + "schema": "address" + }, + value: { + "__michelsonType": "bool", + "schema": "bool" + }, + }, + }, + balance: { + "__michelsonType": "int", + "schema": "int" + }, + paused: { + "__michelsonType": "bool", + "schema": "bool" + }, + selling: { + "__michelsonType": "map", + "schema": { + key: { + "__michelsonType": "address", + "schema": "address" + }, + value: { + "__michelsonType": "big_map", + "schema": { + key: { + "__michelsonType": "nat", + "schema": "nat" + }, + value: { + "__michelsonType": "pair", + "schema": { + fee: { + "__michelsonType": "nat", + "schema": "nat" + }, + owner: { + "__michelsonType": "address", + "schema": "address" + }, + price: { + "__michelsonType": "mutez", + "schema": "mutez" + }, + } + }, + }, + }, + }, + }, + tokenAddress: { + "__michelsonType": "address", + "schema": "address" + }, + } + }); }); it('Test storage parsing', () => { diff --git a/packages/taquito-michelson-encoder/test/sample21.spec.ts b/packages/taquito-michelson-encoder/test/sample21.spec.ts index 3930ca007c..272fddd9d1 100644 --- a/packages/taquito-michelson-encoder/test/sample21.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample21.spec.ts @@ -3,25 +3,42 @@ import { Schema } from '../src/schema/storage'; describe('List token type structure', () => { it('Should extract correct schema for token type list', () => { const storageType = { - prim: 'list', - args: [ - { - prim: 'pair', - args: [ - { prim: 'address', annots: ['%from'] }, - { prim: 'address', annots: ['%to'] }, - ], - }, - ], + prim: 'list', + args: [ + { + prim: 'pair', + args: [ + { prim: 'address', annots: ['%from'] }, + { prim: 'address', annots: ['%to'] }, + ], + }, + ], }; const schema = new Schema(storageType); expect(schema.ExtractSchema()).toEqual({ - list: { + list: { "from": "address", "to": "address" } }); + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'list', + schema: { + __michelsonType: 'pair', + schema: { + "from": { + __michelsonType: "address", + schema: "address" + }, + "to": { + __michelsonType: "address", + schema: "address" + } + } + } + }); + }); }); \ No newline at end of file diff --git a/packages/taquito-michelson-encoder/test/sample21_complex-bigmap.spec.ts b/packages/taquito-michelson-encoder/test/sample21_complex-bigmap.spec.ts index 36c95ca315..4cfa679fb6 100644 --- a/packages/taquito-michelson-encoder/test/sample21_complex-bigmap.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample21_complex-bigmap.spec.ts @@ -2,127 +2,419 @@ import { storage, complex_storage } from '../data/sample_complex_bigmap'; import { Schema } from '../src/schema/storage'; describe('Complex big_map storage', () => { - it('Should extract correct bigmap schema', () => { - const schema = new Schema(storage); + it('Should extract correct bigmap schema', () => { + const schema = new Schema(storage); - expect(schema.ExtractSchema()).toEqual({ - "administrator": "address", - "balances": { - "big_map": { - "key": "address", - "value": { - "approvals": { - "map": { - "key": "address", - "value": "nat" - } + expect(schema.ExtractSchema()).toEqual({ + "administrator": "address", + "balances": { + "big_map": { + "key": "address", + "value": { + "approvals": { + "map": { + "key": "address", + "value": "nat" + } + }, + "balance": "nat" + } + } + }, + "counter": "nat", + "default_expiry": "nat", + "max_expiry": "nat", + "metadata": { + "big_map": { + "key": "string", + "value": "bytes" + } + }, + "paused": "bool", + "permit_expiries": { + "big_map": { + "key": { + "0": "address", + "1": "bytes" + }, + "value": "nat" + } + }, + "permits": { + "big_map": { + "key": { + "0": "address", + "1": "bytes" + }, + "value": "timestamp" + } + }, + "totalSupply": "nat", + "user_expiries": { + "big_map": { + "key": "address", + "value": "nat" + } + } + }); + expect(schema.generateSchema()).toEqual({ + "__michelsonType": "pair", + schema: { + "administrator": { + "__michelsonType": "address", + "schema": "address" + }, + "balances": { + __michelsonType: 'big_map', + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" + }, + "value": { + __michelsonType: 'pair', + schema: { + "approvals": { + "__michelsonType": "map", + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" }, - "balance": "nat" - } - } - }, - "counter": "nat", - "default_expiry": "nat", - "max_expiry": "nat", - "metadata": { - "big_map": { - "key": "string", - "value": "bytes" + "value": { + "__michelsonType": "nat", + "schema": "nat" + } } }, - "paused": "bool", - "permit_expiries": { - "big_map": { - "key": { - "0": "address", - "1": "bytes" - }, - "value": "nat" - } + "balance": { + "__michelsonType": "nat", + "schema": "nat" + } + } + } + } + }, + "counter": { + "__michelsonType": "nat", + "schema": "nat" + }, + "default_expiry": { + "__michelsonType": "nat", + "schema": "nat" + }, + "max_expiry": { + "__michelsonType": "nat", + "schema": "nat" + }, + "metadata": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "string", + "schema": "string" + }, + "value": { + "__michelsonType": "bytes", + "schema": "bytes" + } + } + }, + "paused": { + "__michelsonType": "bool", + "schema": "bool" + }, + "permit_expiries": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "pair", + "schema": { + "0": { + "__michelsonType": "address", + "schema": "address" }, - "permits": { - "big_map": { - "key": { - "0": "address", - "1": "bytes" - }, - "value": "timestamp" - } + "1": { + "__michelsonType": "bytes", + "schema": "bytes" + } + } + }, + "value": { + "__michelsonType": "option", + "schema": { + "__michelsonType": "nat", + "schema": "nat" + } + } + } + }, + "permits": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "pair", + "schema": { + "0": { + "__michelsonType": "address", + "schema": "address" }, - "totalSupply": "nat", - "user_expiries": { - "big_map": { - "key": "address", - "value": "nat" - } + "1": { + "__michelsonType": "bytes", + "schema": "bytes" } + } + }, + "value": { + "__michelsonType": "timestamp", + "schema": "timestamp" + } + } + }, + "totalSupply": { + "__michelsonType": "nat", + "schema": "nat" + }, + "user_expiries": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" + }, + "value": { + "__michelsonType": "option", + "schema": { + "__michelsonType": "nat", + "schema": "nat" + } + } + } + } + } + }); }); - }); - it('Should extract correct bigmap schema for complex key-value pairs', () => { - const schema = new Schema(complex_storage); + it('Should extract correct bigmap schema for complex key-value pairs', () => { + const schema = new Schema(complex_storage); - expect(schema.ExtractSchema()).toEqual({ - "administrator": "address", - "balances": { - "big_map": { + expect(schema.ExtractSchema()).toEqual({ + "administrator": "address", + "balances": { + "big_map": { + "key": "address", + "value": { + "approvals": { + "map": { "key": "address", - "value": { - "approvals": { - "map": { - "key": "address", - "value": "nat" - } - }, - "balance": "nat" - } - } - }, - "counter": "nat", - "default_expiry": "nat", - "max_expiry": "nat", - "metadata": { - "big_map": { - "key": "string", - "value": "bytes" - } + "value": "nat" + } + }, + "balance": "nat" + } + } + }, + "counter": "nat", + "default_expiry": "nat", + "max_expiry": "nat", + "metadata": { + "big_map": { + "key": "string", + "value": "bytes" + } + }, + "paused": "bool", + "permit_expiries": { + "big_map": { + "key": { + "big_map": { + "key": { + "0": "address", + "1": "bytes" }, - "paused": "bool", - "permit_expiries": { - "big_map": { - "key": { - "big_map": { - "key": { - "0": "address", - "1": "bytes" - }, - "value": "bytes" + "value": "bytes" + } + }, + "value": "nat" + } + }, + "permits": { + "big_map": { + "key": { + "big_map": { + "key": "address", + "value": { + "0": "address", + "1": "bytes" + } + } + }, + "value": "timestamp" + } + }, + "totalSupply": "nat", + "user_expiries": { + "big_map": { + "key": "address", + "value": "nat" + } + } + }); + + expect(schema.generateSchema()).toEqual({ + "__michelsonType": "pair", + "schema": { + "administrator": { + "__michelsonType": "address", + "schema": "address" + }, + "balances": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" + }, + "value": { + "__michelsonType": "pair", + "schema": { + "approvals": { + "__michelsonType": "map", + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" + }, + "value": { + "__michelsonType": "nat", + "schema": "nat" + } } }, - "value": "nat" + "balance": { + "__michelsonType": "nat", + "schema": "nat" } - }, - "permits": { - "big_map": { + } + } + } + }, + "counter": { + "__michelsonType": "nat", + "schema": "nat" + }, + "default_expiry": { + "__michelsonType": "nat", + "schema": "nat" + }, + "max_expiry": { + "__michelsonType": "nat", + "schema": "nat" + }, + "metadata": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "string", + "schema": "string" + }, + "value": { + "__michelsonType": "bytes", + "schema": "bytes" + } + } + }, + "paused": { + "__michelsonType": "bool", + "schema": "bool" + }, + "permit_expiries": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "big_map", + "schema": { "key": { - "big_map": { - "key": "address", - "value": { - "0": "address", - "1": "bytes" - } + "__michelsonType": "pair", + "schema": { + "0": { + "__michelsonType": "address", + "schema": "address" + }, + "1": { + "__michelsonType": "bytes", + "schema": "bytes" + } } }, - "value": "timestamp" + "value": { + "__michelsonType": "bytes", + "schema": "bytes" } - }, - "totalSupply": "nat", - "user_expiries": { - "big_map": { - "key": "address", - "value": "nat" + } + }, + "value": { + "__michelsonType": "option", + "schema": { + "__michelsonType": "nat", + "schema": "nat" + } + } + } + }, + "permits": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" + }, + "value": { + "__michelsonType": "pair", + "schema": { + "0": { + "__michelsonType": "address", + "schema": "address" + }, + "1": { + "__michelsonType": "bytes", + "schema": "bytes" + } + } } } + }, + "value": { + "__michelsonType": "timestamp", + "schema": "timestamp" + } + } + }, + "totalSupply": { + "__michelsonType": "nat", + "schema": "nat" + }, + "user_expiries": { + "__michelsonType": "big_map", + "schema": { + "key": { + "__michelsonType": "address", + "schema": "address" + }, + "value": { + "__michelsonType": "option", + "schema": { + "__michelsonType": "nat", + "schema": "nat" + } + } + } + } + } + }); + }); - }); }); diff --git a/packages/taquito-michelson-encoder/test/sample22.spec.ts b/packages/taquito-michelson-encoder/test/sample22.spec.ts index 3930ca007c..86483a9931 100644 --- a/packages/taquito-michelson-encoder/test/sample22.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample22.spec.ts @@ -23,5 +23,22 @@ describe('List token type structure', () => { } }); + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'list', + schema: { + __michelsonType: 'pair', + schema: { + "from": { + __michelsonType: "address", + schema: "address" + }, + "to": { + __michelsonType: "address", + schema: "address" + } + } + } + }); + }); }); \ No newline at end of file diff --git a/packages/taquito-michelson-encoder/test/sample6.spec.ts b/packages/taquito-michelson-encoder/test/sample6.spec.ts index d4b432cb2f..ad0a800d38 100644 --- a/packages/taquito-michelson-encoder/test/sample6.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample6.spec.ts @@ -13,9 +13,9 @@ describe('Schema test', () => { expect(schema.ExtractSchema()).toEqual({ key_info: { key_groups: { - list: { + list: { "group_threshold": "nat", - "signatories": { + "signatories": { list: "key", }, }, @@ -38,6 +38,96 @@ describe('Schema test', () => { }, replay_counter: 'nat', }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: "pair", + schema: { + key_info: { + __michelsonType: "pair", + schema: { + key_groups: { + __michelsonType: "list", + schema: { + __michelsonType: "pair", + schema: { + group_threshold: { + __michelsonType: "nat", + schema: "nat" + }, + signatories: { + __michelsonType: "list", + schema: { + __michelsonType: "key", + schema: "key" + }, + }, + } + }, + }, + overall_threshold: { + __michelsonType: "nat", + schema: "nat" + }, + } + }, + pour_info: { + __michelsonType: "option", + schema: { + __michelsonType: "pair", + schema: { + pour_authorizer: { + __michelsonType: "key", + schema: "key" + }, + pour_dest: { + __michelsonType: "contract", + schema: { + parameter: { + __michelsonType: "unit", + schema: "unit" + } + } + }, + } + } + }, + vesting: { + __michelsonType: "pair", + schema: { + vesting_quantities: { + __michelsonType: "pair", + schema: { + vested_balance: { + __michelsonType: "mutez", + schema: "mutez" + }, + vesting_increment: { + __michelsonType: "mutez", + schema: "mutez" + }, + } + }, + vesting_schedule: { + __michelsonType: "pair", + schema: { + next_payout: { + __michelsonType: "timestamp", + schema: "timestamp" + }, + payout_interval: { + __michelsonType: "int", + schema: "int" + }, + } + }, + } + }, + replay_counter: { + __michelsonType: "nat", + schema: "nat" + }, + } + }); }); it('Should encode storage properly', () => { @@ -143,9 +233,9 @@ describe('Schema test', () => { Set_delegate: 'key_hash', Set_keys: { key_groups: { - list: { + list: { "group_threshold": "nat", - "signatories": { + "signatories": { list: "key", }, }, @@ -162,16 +252,135 @@ describe('Schema test', () => { }, }, signatures: { - list: { - list: "signature", - }, - }, + list: { + list: "signature", + }, + }, }, }); + expect(schema.generateSchema()).toEqual({ + __michelsonType: "or", + schema: { + Pour: { + __michelsonType: "option", + schema: { + __michelsonType: "pair", + schema: { + pour_amount: { + __michelsonType: "mutez", + schema: 'mutez' + }, + pour_auth: { + __michelsonType: "signature", + schema: 'signature' + } + } + } + }, + Action: { + __michelsonType: "pair", + schema: { + action_input: { + __michelsonType: "or", + schema: { + Set_delegate: { + __michelsonType: "option", + schema: { + __michelsonType: "key_hash", + schema: "key_hash" + } + }, + Set_keys: { + __michelsonType: "pair", + schema: { + key_groups: { + __michelsonType: "list", + schema: { + __michelsonType: "pair", + schema: { + group_threshold: { + __michelsonType: "nat", + schema: "nat" + }, + signatories: { + __michelsonType: "list", + schema: { + __michelsonType: "key", + schema: "key" + }, + } + } + }, + }, + overall_threshold: { + __michelsonType: "nat", + schema: "nat" + }, + } + }, + Set_pour: { + __michelsonType: "option", + schema: { + __michelsonType: "pair", + schema: { + pour_authorizer: { + __michelsonType: "key", + schema: 'key' + }, + pour_dest: { + __michelsonType: "contract", + schema: { + parameter: { + __michelsonType: "unit", + schema: 'unit' + } + } + } + } + } + }, + Transfer: { + __michelsonType: "pair", + schema: { + dest: { + __michelsonType: "contract", + schema: { + parameter: { + __michelsonType: "unit", + schema: 'unit' + } + } + }, + transfer_amount: { + __michelsonType: "mutez", + schema: 'mutez' + }, + } + }, + } + }, + signatures: { + __michelsonType: "list", + schema: { + __michelsonType: "list", + schema: { + __michelsonType: "option", + schema: { + __michelsonType: "signature", + schema: 'signature' + } + } + }, + }, + } + }, + } + }); + const signatures = schema.ExtractSignatures(); expect(signatures).toContainEqual(['Pour', 'signature', 'mutez']); - expect(signatures).toContainEqual(['Action', 'Set_delegate', 'key_hash', {"list": {"list": "signature"}}]); + expect(signatures).toContainEqual(['Action', 'Set_delegate', 'key_hash', { "list": { "list": "signature" } }]); }); it('Should encode parameter properly', () => { diff --git a/packages/taquito-michelson-encoder/test/sample8.spec.ts b/packages/taquito-michelson-encoder/test/sample8.spec.ts index 11c802d6b7..2ad0a884f0 100644 --- a/packages/taquito-michelson-encoder/test/sample8.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample8.spec.ts @@ -7,6 +7,10 @@ describe('Schema test', () => { const schema = new ParameterSchema(params8); const storage = schema.ExtractSchema(); expect(storage).toEqual('string'); + expect(schema.generateSchema()).toEqual({ + __michelsonType: "string", + schema: 'string' + }); expect({ string: 'test' }).toEqual(schema.Encode('test')); expect(schema.isMultipleEntryPoint).toBeFalsy(); diff --git a/packages/taquito-michelson-encoder/test/sample9_lambda.spec.ts b/packages/taquito-michelson-encoder/test/sample9_lambda.spec.ts index 99e0a75b78..3e8843f698 100644 --- a/packages/taquito-michelson-encoder/test/sample9_lambda.spec.ts +++ b/packages/taquito-michelson-encoder/test/sample9_lambda.spec.ts @@ -34,6 +34,79 @@ describe('Schema test', () => { }, }, }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'or', + schema: { + '0': { + __michelsonType: "pair", + schema: { + '0': { + __michelsonType: "address", + schema: 'address' + }, + '1': { + __michelsonType: "string", + schema: 'string' + }, + '2': { + __michelsonType: "option", + schema: { + __michelsonType: "bytes", + schema: 'bytes' + } + }, + } + }, + '1': { + __michelsonType: "mutez", + schema: 'mutez' + }, + '2': { + __michelsonType: "pair", + schema: { + '2': { + __michelsonType: "address", + schema: 'address' + }, + '3': { + __michelsonType: "bool", + schema: 'bool' + }, + } + }, + '3': { + __michelsonType: "lambda", + schema: { + parameters: { + __michelsonType: "pair", + schema: { + 3: { + __michelsonType: "address", + schema: 'address' + }, + 4: { + __michelsonType: "string", + schema: 'string' + }, + 5: { + __michelsonType: "option", + schema: { + __michelsonType: "bytes", + schema: 'bytes' + } + }, + } + }, + returns: { + __michelsonType: "operation", + schema: 'operation' + }, + }, + }, + } + }); + expect({ args: [ { diff --git a/packages/taquito-michelson-encoder/test/tokens/address.spec.ts b/packages/taquito-michelson-encoder/test/tokens/address.spec.ts index 01fd939ecd..46c451bcb1 100644 --- a/packages/taquito-michelson-encoder/test/tokens/address.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/address.spec.ts @@ -37,4 +37,13 @@ describe('Address token', () => { } }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'address', + schema: 'address' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/bigmap.spec.ts b/packages/taquito-michelson-encoder/test/tokens/bigmap.spec.ts index 7d776adb33..1427cc66de 100644 --- a/packages/taquito-michelson-encoder/test/tokens/bigmap.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/bigmap.spec.ts @@ -2,30 +2,37 @@ import { createToken } from '../../src/tokens/createToken'; import { expectMichelsonMap } from '../utils'; describe('BigMap', () => { + const bigMap = createToken({ prim: 'big_map', args: [{ prim: 'address' }, { prim: 'int' }] }, 0); + it('Should use custom semantic when provided', () => { - const bigMap = createToken( - { prim: 'big_map', args: [{ prim: 'address' }, { prim: 'int' }] }, - 0 - ); const result = bigMap.Execute({ int: 1 } as any, { big_map: () => 'working' }); expect(result).toBe('working'); }); it('Should use default semantic when omitted', () => { - const bigMap = createToken( - { prim: 'big_map', args: [{ prim: 'address' }, { prim: 'int' }] }, - 0 - ); const result = bigMap.Execute([]); expect(result).toEqual(expectMichelsonMap()); }); it('Should use default semantic (return id) when omitted', () => { - const bigMap = createToken( - { prim: 'big_map', args: [{ prim: 'address' }, { prim: 'int' }] }, - 0 - ); const result = bigMap.Execute({ int: 12 } as any); expect(result).toEqual(12); }); + + it('Should generate the schema properly', () => { + expect(bigMap.generateSchema()).toEqual({ + __michelsonType: 'big_map', + schema: { + key: { + __michelsonType: 'address', + schema: 'address' + }, + value: { + __michelsonType: 'int', + schema: 'int' + } + } + }); + }); + }); diff --git a/packages/taquito-michelson-encoder/test/tokens/bls12-381-fr.spec.ts b/packages/taquito-michelson-encoder/test/tokens/bls12-381-fr.spec.ts index ef7a34f742..bd7f71311b 100644 --- a/packages/taquito-michelson-encoder/test/tokens/bls12-381-fr.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/bls12-381-fr.spec.ts @@ -73,6 +73,10 @@ describe('Bls12-381-fr token', () => { describe('ExtractSchema', () => { it('test schema', () => { expect(token.ExtractSchema()).toEqual('bls12_381_fr'); + expect(token.generateSchema()).toEqual({ + __michelsonType: 'bls12_381_fr', + schema: 'bls12_381_fr' + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/bls12-381-g1.spec.ts b/packages/taquito-michelson-encoder/test/tokens/bls12-381-g1.spec.ts index 811df21c77..3a8bdf6a43 100644 --- a/packages/taquito-michelson-encoder/test/tokens/bls12-381-g1.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/bls12-381-g1.spec.ts @@ -78,6 +78,11 @@ describe('Bls12-381-g1 token', () => { describe('ExtractSchema', () => { it('test schema', () => { expect(token.ExtractSchema()).toEqual('bls12_381_g1'); + + expect(token.generateSchema()).toEqual({ + __michelsonType: 'bls12_381_g1', + schema: 'bls12_381_g1' + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/bls12-381-g2.spec.ts b/packages/taquito-michelson-encoder/test/tokens/bls12-381-g2.spec.ts index a18b20398d..bd9717e3b9 100644 --- a/packages/taquito-michelson-encoder/test/tokens/bls12-381-g2.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/bls12-381-g2.spec.ts @@ -78,6 +78,11 @@ describe('Bls12-381-g2 token', () => { describe('ExtractSchema', () => { it('test schema', () => { expect(token.ExtractSchema()).toEqual('bls12_381_g2'); + + expect(token.generateSchema()).toEqual({ + __michelsonType: 'bls12_381_g2', + schema: 'bls12_381_g2' + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/bytes.spec.ts b/packages/taquito-michelson-encoder/test/tokens/bytes.spec.ts index 2ec9f42b42..3d41634be1 100644 --- a/packages/taquito-michelson-encoder/test/tokens/bytes.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/bytes.spec.ts @@ -50,4 +50,13 @@ describe('Bytes token', () => { } }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'bytes', + schema: 'bytes' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/chain_id.spec.ts b/packages/taquito-michelson-encoder/test/tokens/chain_id.spec.ts index 0a5af6bc02..a61b478e10 100644 --- a/packages/taquito-michelson-encoder/test/tokens/chain_id.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/chain_id.spec.ts @@ -28,4 +28,13 @@ describe('Chain ID token', () => { expect(() => token.Encode([{}])).toThrowError(ChainIDValidationError); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'chain_id', + schema: 'chain_id' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/chest-key.spec.ts b/packages/taquito-michelson-encoder/test/tokens/chest-key.spec.ts index 2fdddf727b..b5c30842c9 100644 --- a/packages/taquito-michelson-encoder/test/tokens/chest-key.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/chest-key.spec.ts @@ -76,8 +76,13 @@ describe('ChestKey token', () => { }); describe('ExtractSchema', () => { - it('test schema', () => { + it('Should generate the schema properly.', () => { expect(token.ExtractSchema()).toEqual('chest_key'); + + expect(token.generateSchema()).toEqual({ + __michelsonType: 'chest_key', + schema: 'chest_key' + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/chest.spec.ts b/packages/taquito-michelson-encoder/test/tokens/chest.spec.ts index 07bffdd00d..9031a82df6 100644 --- a/packages/taquito-michelson-encoder/test/tokens/chest.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/chest.spec.ts @@ -76,8 +76,13 @@ describe('Chest token', () => { }); describe('ExtractSchema', () => { - it('test schema', () => { + it('Should generate the schema properly.', () => { expect(token.ExtractSchema()).toEqual('chest'); + + expect(token.generateSchema()).toEqual({ + __michelsonType: 'chest', + schema: 'chest' + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/constant.spec.ts b/packages/taquito-michelson-encoder/test/tokens/constant.spec.ts index d88f7c4374..c3de6d42e0 100644 --- a/packages/taquito-michelson-encoder/test/tokens/constant.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/constant.spec.ts @@ -112,4 +112,15 @@ describe('Global constant token', () => { }); }); + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'constant', + schema: { + hash: 'expru5X5fvCer8tbRkSAtwyVCs9FUCq46JQG7QCAkhZSumjbZBUGzb' + } + }); + }); + }); + }); diff --git a/packages/taquito-michelson-encoder/test/tokens/int.spec.ts b/packages/taquito-michelson-encoder/test/tokens/int.spec.ts index 02999eae6a..649fee6a7a 100644 --- a/packages/taquito-michelson-encoder/test/tokens/int.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/int.spec.ts @@ -35,17 +35,26 @@ describe('Int token', () => { }); describe('ToBigMapKey', () => { - it('accepts a number as parameter', () => { + it('accepts a number as parameter', () => { expect(token.ToBigMapKey(0)).toEqual({ key: { int: '0' }, type: { prim: IntToken.prim }, }); }); - it('accepts a string as parameter', () => { + it('accepts a string as parameter', () => { expect(token.ToBigMapKey('0')).toEqual({ key: { int: '0' }, type: { prim: IntToken.prim }, - }); + }); + }); + }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'int', + schema: 'int' + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/key.spec.ts b/packages/taquito-michelson-encoder/test/tokens/key.spec.ts index b10c9212a1..7eca7704be 100644 --- a/packages/taquito-michelson-encoder/test/tokens/key.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/key.spec.ts @@ -86,4 +86,13 @@ describe('Key token', () => { expect(token.compare("p2pk65shUHKhx7zUSF7e8KZ2inmQ5aMS4jRBUmK6aCis4oaHoiWPXoT", "sppk7aTKnmX5WV17KPo3LanjfPLoXTuNjkQTdLx2bYDqHPLVVCbSwoj")).toEqual(1); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'key', + schema: 'key' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/key_hash.spec.ts b/packages/taquito-michelson-encoder/test/tokens/key_hash.spec.ts index 8bf1da236e..4f2bde5590 100644 --- a/packages/taquito-michelson-encoder/test/tokens/key_hash.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/key_hash.spec.ts @@ -40,4 +40,13 @@ describe('KeyHash token', () => { } }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'key_hash', + schema: 'key_hash' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/lambda.spec.ts b/packages/taquito-michelson-encoder/test/tokens/lambda.spec.ts index 34a121bc46..24a543f9ce 100644 --- a/packages/taquito-michelson-encoder/test/tokens/lambda.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/lambda.spec.ts @@ -26,8 +26,25 @@ describe('Lambda token', () => { lambda: { parameters: 'unit', returns: { - list: "operation", - } + list: "operation", + } + } + }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'lambda', + schema: { + parameters: { + __michelsonType: 'unit', + schema: 'unit' + }, + returns: { + __michelsonType: 'list', + schema: { + __michelsonType: 'operation', + schema: 'operation' + } + } } }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/map.spec.ts b/packages/taquito-michelson-encoder/test/tokens/map.spec.ts index a66b0d53a1..8e85cc432d 100644 --- a/packages/taquito-michelson-encoder/test/tokens/map.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/map.spec.ts @@ -634,6 +634,24 @@ describe('Map token', () => { ]); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'map', + schema: { + key: { + __michelsonType: 'string', + schema: 'string' + }, + value: { + __michelsonType: 'int', + schema: 'int' + } + } + }); + }); + }); }); describe('Map token with pair', () => { @@ -731,6 +749,33 @@ describe('Map token with pair', () => { expect(result.get({ 1: 'test', 0: 'test1' }).toString()).toEqual('3'); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'map', + schema: { + key: { + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'string', + schema: 'string' + }, + 1: { + __michelsonType: 'string', + schema: 'string' + } + } + }, + value: { + __michelsonType: 'int', + schema: 'int' + } + } + }); + }); + }); }); describe('Map token with annotated pair', () => { @@ -835,6 +880,31 @@ describe('Map token with annotated pair', () => { expect(result.get({ test: 'test1', test2: 'test' }).toString()).toEqual('3'); }); }); + + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'map', + schema: { + key: { + __michelsonType: 'pair', + schema: { + test: { + __michelsonType: 'string', + schema: 'string' + }, + test2: { + __michelsonType: 'string', + schema: 'string' + } + } + }, + value: { + __michelsonType: 'int', + schema: 'int' + } + } + }); + }); }); describe('Map token with complex pair', () => { @@ -1096,6 +1166,59 @@ describe('Map token with complex pair', () => { ); }); }); + + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'map', + schema: { + key: { + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'int', + schema: 'int' + }, + 1: { + __michelsonType: 'nat', + schema: 'nat' + }, + 2: { + __michelsonType: 'string', + schema: 'string' + }, + 3: { + __michelsonType: 'bytes', + schema: 'bytes' + }, + 4: { + __michelsonType: 'mutez', + schema: 'mutez' + }, + 5: { + __michelsonType: 'bool', + schema: 'bool' + }, + 6: { + __michelsonType: 'key_hash', + schema: 'key_hash' + }, + 7: { + __michelsonType: 'timestamp', + schema: 'timestamp' + }, + 8: { + __michelsonType: 'address', + schema: 'address' + }, + } + }, + value: { + __michelsonType: 'int', + schema: 'int' + } + } + }); + }); }); describe('Map token with nat as key and nat as value', () => { diff --git a/packages/taquito-michelson-encoder/test/tokens/mutez.spec.ts b/packages/taquito-michelson-encoder/test/tokens/mutez.spec.ts index 13ac88c901..f810b3f382 100644 --- a/packages/taquito-michelson-encoder/test/tokens/mutez.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/mutez.spec.ts @@ -47,4 +47,13 @@ describe('Mutez token', () => { }); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'mutez', + schema: 'mutez' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/nat.spec.ts b/packages/taquito-michelson-encoder/test/tokens/nat.spec.ts index 32c7b8139b..01c4406405 100644 --- a/packages/taquito-michelson-encoder/test/tokens/nat.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/nat.spec.ts @@ -56,4 +56,13 @@ describe('Nat token', () => { }); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'nat', + schema: 'nat' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/never.spec.ts b/packages/taquito-michelson-encoder/test/tokens/never.spec.ts index ea083974c7..defa3401d8 100644 --- a/packages/taquito-michelson-encoder/test/tokens/never.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/never.spec.ts @@ -46,12 +46,29 @@ describe('Never token', () => { const schema = new ParameterSchema({ prim: 'never' }); const result = schema.ExtractSchema(); expect(result).toEqual('never'); + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'never', + schema: 'never' + }); }); it('Never parameter are encoded properly', () => { const schema = new ParameterSchema({ "prim": "pair", "args": [{ "prim": "nat" }, { "prim": "never" }] }); const result = schema.ExtractSchema(); - expect(result).toEqual({0: 'nat', 1: 'never'}); + expect(result).toEqual({ 0: 'nat', 1: 'never' }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'nat', + schema: 'nat' + }, 1: { + __michelsonType: 'never', + schema: 'never' + } + } + }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/option.spec.ts b/packages/taquito-michelson-encoder/test/tokens/option.spec.ts index aabb65df08..73fb44f873 100644 --- a/packages/taquito-michelson-encoder/test/tokens/option.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/option.spec.ts @@ -74,16 +74,28 @@ describe('Option token', () => { describe('Tokey', () => { it('Should transform Michelson bytes data to a key of type string', () => { - expect(token.ToKey({ prim: 'Some', args: [{ int: '4' }]}).toString()).toEqual('4'); + expect(token.ToKey({ prim: 'Some', args: [{ int: '4' }] }).toString()).toEqual('4'); }); }); describe('ToBigMapKey', () => { it('Should transform option value to a Michelson big map key', () => { expect(token.ToBigMapKey(5)).toEqual({ - key: { prim: 'Some', args: [{ int: '5' }]}, + key: { prim: 'Some', args: [{ int: '5' }] }, type: { prim: 'option', args: [{ prim: 'int' }] } }); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'option', + schema: { + __michelsonType: 'int', + schema: 'int' + } + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/or.spec.ts b/packages/taquito-michelson-encoder/test/tokens/or.spec.ts index 5f8c0e1a9b..bb5a2c8f49 100644 --- a/packages/taquito-michelson-encoder/test/tokens/or.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/or.spec.ts @@ -9,6 +9,7 @@ describe('Or token', () => { let tokenComplexNoAnnots: OrToken; let tokenNestedOr: OrToken; let tokenNestedOrWithoutAnnot: OrToken; + let tokenOrWithOption: OrToken; beforeEach(() => { token = createToken({ prim: 'or', args: [{ prim: 'int', annots: ['intTest'] }, { prim: 'string', annots: ['stringTest'] }], annots: [] }, 0) as OrToken; tokenNoAnnots = createToken({ prim: 'or', args: [{ prim: 'int' }, { prim: 'string' }], annots: [] }, 0) as OrToken; @@ -16,6 +17,7 @@ describe('Or token', () => { tokenComplexNoAnnots = createToken({ prim: 'or', args: [{ prim: 'or', args: [{ prim: 'pair', args: [{ prim: 'nat' }, { prim: 'pair', args: [{ prim: 'nat' }, { prim: 'timestamp' }] }] }, { prim: 'pair', args: [{ prim: 'pair', args: [{ prim: 'nat' }, { prim: 'mutez' }] }, { prim: 'pair', args: [{ prim: 'nat' }, { prim: 'timestamp' }] }] }] }, { prim: 'or', args: [{ prim: 'pair', args: [{ prim: 'nat' }, { prim: 'timestamp' }] }, { prim: 'or', args: [{ prim: 'pair', args: [{ prim: 'nat' }, { prim: 'pair', args: [{ prim: 'mutez' }, { prim: 'timestamp' }] }] }, { prim: 'nat' }] }] }] }, 0) as OrToken; tokenNestedOr = createToken({ "prim": "or", "args": [{ "prim": "or", "args": [{ "prim": "or", "args": [{ "prim": "address", "annots": ["%myAddress"] }, { "prim": "bytes", "annots": ["%myBytes"] }] }, { "prim": "or", "args": [{ "prim": "int", "annots": ["%myInt"] }, { "prim": "nat", "annots": ["%myNat"] }] }] }, { "prim": "or", "args": [{ "prim": "or", "args": [{ "prim": "pair", "args": [{ "prim": "nat" }, { "prim": "int" }], "annots": ["%myPair"] }, { "prim": "string", "annots": ["%myString"] }] }, { "prim": "mutez", "annots": ["%myTez"] }] }] }, 0) as OrToken; tokenNestedOrWithoutAnnot = createToken({ "prim": "or", "args": [{ "prim": "or", "args": [{ "prim": "or", "args": [{ "prim": "address" }, { "prim": "bytes" }] }, { "prim": "or", "args": [{ "prim": "int" }, { "prim": "nat" }] }] }, { "prim": "or", "args": [{ "prim": "or", "args": [{ "prim": "pair", "args": [{ "prim": "nat" }, { "prim": "int" }] }, { "prim": "string" }] }, { "prim": "mutez" }] }] }, 0) as OrToken; + tokenOrWithOption = createToken({ prim: 'or', args: [{ prim: 'int' }, { prim: 'or', args: [{ prim: 'nat' }, { prim: 'or', args: [{ prim: 'mutez' }, { prim: 'option', args: [{ prim: 'or', args: [{ prim: 'int' }, { prim: 'string' }], annots: [] }], annots: [] }], annots: [] }], annots: [] }], annots: [] }, 0) as OrToken; }); describe('EncodeObject', () => { @@ -37,6 +39,8 @@ describe('Or token', () => { expect(tokenComplex.EncodeObject({ option2: { 2: 3, 3: 'test' } })).toEqual({ prim: 'Right', args: [{ prim: 'Left', args: [{ prim: 'Pair', args: [{ int: '3' }, { string: 'test' }] }] }] }); expect(tokenComplex.EncodeObject({ option3: { 3: 4, 4: 3, 5: "2019-09-06T15:08:29.000Z" } })).toEqual({ prim: 'Right', args: [{ prim: 'Right', args: [{ prim: 'Left', args: [{ prim: 'Pair', args: [{ int: '4' }, { prim: 'Pair', args: [{ int: '3' }, { string: "2019-09-06T15:08:29.000Z" }] }] }] }] }] }); expect(tokenComplex.EncodeObject({ option4: 4 })).toEqual({ prim: 'Right', args: [{ prim: 'Right', args: [{ prim: 'Right', args: [{ int: '4' }] }] }] }); + + expect(tokenOrWithOption.EncodeObject({ 3: { 1: 'test' } })).toEqual({ prim: 'Right', args: [{ prim: 'Right', args: [{ prim: 'Right', args: [{ prim: 'Some', args: [{ prim: 'Right', args: [{ string: 'test' }] }] }] }] }] }); }); }); @@ -67,8 +71,36 @@ describe('Or token', () => { it('Should extract schema properly', () => { expect(token.ExtractSchema()).toEqual({ intTest: 'int', stringTest: 'string' }); + expect(token.generateSchema()).toEqual({ + __michelsonType: 'or', + schema: { + intTest: { + __michelsonType: 'int', + schema: 'int' + }, + stringTest: { + __michelsonType: 'string', + schema: 'string' + } + } + }); + expect(tokenNoAnnots.ExtractSchema()).toEqual({ 0: 'int', 1: 'string' }); + expect(tokenNoAnnots.generateSchema()).toEqual({ + __michelsonType: 'or', + schema: { + 0: { + __michelsonType: 'int', + schema: 'int' + }, + 1: { + __michelsonType: 'string', + schema: 'string' + } + } + }); + expect(tokenComplexNoAnnots.ExtractSchema()).toEqual({ 0: { 0: 'nat', 1: 'nat', 2: "timestamp" }, 1: { 1: 'nat', 2: 'mutez', 3: 'nat', 4: "timestamp" }, @@ -77,6 +109,84 @@ describe('Or token', () => { 4: 'nat' }); + expect(tokenComplexNoAnnots.generateSchema()).toEqual({ + __michelsonType: 'or', + schema: { + 0: { + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'nat', + schema: 'nat' + }, + 1: { + __michelsonType: 'nat', + schema: 'nat' + }, + 2: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + 1: { + __michelsonType: 'pair', + schema: { + 1: { + __michelsonType: 'nat', + schema: 'nat' + }, + 2: { + __michelsonType: 'mutez', + schema: 'mutez' + }, + 3: { + __michelsonType: 'nat', + schema: 'nat' + }, + 4: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + 2: { + __michelsonType: 'pair', + schema: { + 2: { + __michelsonType: 'nat', + schema: 'nat' + }, + 3: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + 3: { + __michelsonType: 'pair', + schema: { + 3: { + __michelsonType: 'nat', + schema: 'nat' + }, + 4: { + __michelsonType: 'mutez', + schema: 'mutez' + }, + 5: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + 4: { + __michelsonType: 'nat', + schema: 'nat' + } + } + }); + expect(tokenComplex.ExtractSchema()).toEqual({ option0: { 0: 'nat', 1: 'nat', 2: "timestamp" }, option1: { 1: 'nat', 2: 'mutez', 3: 'nat', 4: "timestamp" }, @@ -84,6 +194,119 @@ describe('Or token', () => { option3: { 3: 'nat', 4: 'mutez', 5: "timestamp" }, option4: 'nat' }); + + expect(tokenComplex.generateSchema()).toEqual({ + __michelsonType: 'or', + schema: { + option0: { + __michelsonType: 'pair', + schema: { + 0: { + __michelsonType: 'nat', + schema: 'nat' + }, + 1: { + __michelsonType: 'nat', + schema: 'nat' + }, + 2: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + option1: { + __michelsonType: 'pair', + schema: { + 1: { + __michelsonType: 'nat', + schema: 'nat' + }, + 2: { + __michelsonType: 'mutez', + schema: 'mutez' + }, + 3: { + __michelsonType: 'nat', + schema: 'nat' + }, + 4: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + option2: { + __michelsonType: 'pair', + schema: { + 2: { + __michelsonType: 'nat', + schema: 'nat' + }, + 3: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + option3: { + __michelsonType: 'pair', + schema: { + 3: { + __michelsonType: 'nat', + schema: 'nat' + }, + 4: { + __michelsonType: 'mutez', + schema: 'mutez' + }, + 5: { + __michelsonType: 'timestamp', + schema: 'timestamp' + } + } + }, + option4: { + __michelsonType: 'nat', + schema: 'nat' + } + } + }); + + expect(tokenOrWithOption.generateSchema()).toEqual({ + __michelsonType: 'or', + schema: { + 0: { + __michelsonType: 'int', + schema: 'int' + }, + 1: { + __michelsonType: 'nat', + schema: 'nat' + }, + 2: { + __michelsonType: 'mutez', + schema: 'mutez' + }, + 3: { + __michelsonType: 'option', + schema: { + __michelsonType: 'or', + schema: { + 0: { + __michelsonType: 'int', + schema: 'int' + }, + 1: { + __michelsonType: 'string', + schema: 'string' + }, + } + } + }, + } + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/pair.spec.ts b/packages/taquito-michelson-encoder/test/tokens/pair.spec.ts index d8c5f1717d..2da883c65a 100644 --- a/packages/taquito-michelson-encoder/test/tokens/pair.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/pair.spec.ts @@ -2,15 +2,15 @@ import { createToken } from '../../src/tokens/createToken'; import { PairToken } from '../../src/tokens/pair'; describe('Pair token', () => { + const token = createToken( + { + prim: 'pair', + args: [{ prim: 'int', annots: ['test'] }, { prim: 'string', annots: ['test2'] }], + }, + 0 + ) as PairToken; describe('Compare', () => { test('Compare simple pair', () => { - const token = createToken( - { - prim: 'pair', - args: [{ prim: 'int', annots: ['test'] }, { prim: 'string', annots: ['test2'] }], - }, - 0 - ) as PairToken; expect(token.compare({ test: 1, test2: 'test' }, { test: 2, test2: 'test' })).toEqual(-1); expect(token.compare({ test: 3, test2: 'test' }, { test: 2, test2: 'test' })).toEqual(1); @@ -22,13 +22,6 @@ describe('Pair token', () => { describe('ToBigMapKey', () => { test('Simple pair to big map key', () => { - const token = createToken( - { - prim: 'pair', - args: [{ prim: 'int', annots: ['test'] }, { prim: 'string', annots: ['test2'] }], - }, - 0 - ) as PairToken; const { key, type } = token.ToBigMapKey({ test: 1, test2: 'test' }); expect(key).toEqual({ prim: 'Pair', args: [{ int: '1' }, { string: 'test' }] }); expect(type).toEqual({ prim: 'pair', args: [{ prim: 'int' }, { prim: 'string' }] }); @@ -59,4 +52,22 @@ describe('Pair token', () => { }); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + test: { + __michelsonType: 'int', + schema: 'int' + }, + test2: { + __michelsonType: 'string', + schema: 'string' + } + } + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/sapling-transaction.spec.ts b/packages/taquito-michelson-encoder/test/tokens/sapling-transaction.spec.ts index 8ef3225992..2f93bd1333 100644 --- a/packages/taquito-michelson-encoder/test/tokens/sapling-transaction.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/sapling-transaction.spec.ts @@ -95,6 +95,13 @@ describe('Sapling Transaction token', () => { expect(token.ExtractSchema()).toEqual({ sapling_transaction: { 'memo-size': 8 }, }); + + expect(token.generateSchema()).toEqual({ + __michelsonType: 'sapling_transaction', + schema: { + memoSize: '8' + }, + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/sapling_state.spec.ts b/packages/taquito-michelson-encoder/test/tokens/sapling_state.spec.ts index d5490e7329..de7eb13fdc 100644 --- a/packages/taquito-michelson-encoder/test/tokens/sapling_state.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/sapling_state.spec.ts @@ -47,6 +47,13 @@ describe('Sapling Transaction token', () => { expect(token.ExtractSchema()).toEqual({ sapling_state: { 'memo-size': 8 }, }); + + expect(token.generateSchema()).toEqual({ + __michelsonType: 'sapling_state', + schema: { + memoSize: '8' + }, + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/signature.spec.ts b/packages/taquito-michelson-encoder/test/tokens/signature.spec.ts index e1567634ae..5b8434fbfe 100644 --- a/packages/taquito-michelson-encoder/test/tokens/signature.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/signature.spec.ts @@ -33,4 +33,13 @@ describe('Signature token', () => { expect(token.compare('edsigteqgHGYbzsxxFmQjGSf9eeNjTML4g6GBqryKvy7uy6y2XczT6C3ehhfzCBgQBdAMy9NLoD6MZVzCUbtSUoSC1iWAgPXGdW', 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg')).toEqual(-1); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'signature', + schema: 'signature' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/ticket.spec.ts b/packages/taquito-michelson-encoder/test/tokens/ticket.spec.ts index fea7efe3b1..9eaff50626 100644 --- a/packages/taquito-michelson-encoder/test/tokens/ticket.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/ticket.spec.ts @@ -24,22 +24,22 @@ describe('Ticket token', () => { let tokenTicketUnit: TicketToken; beforeEach(() => { - tokenTicketNat = createToken({"prim":"ticket","args":[{"prim":"nat"}],"annots":["%receive"]}, 0) as TicketToken; - tokenTicketTimestamp = createToken({"prim":"ticket","args":[{"prim":"timestamp"}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketAddress = createToken({"prim":"ticket","args":[{"prim":"address"}]}, 0) as TicketToken; - tokenTicketBool = createToken({"prim":"ticket","args":[{"prim":"bool"}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketBytes = createToken({"prim":"ticket","args":[{"prim":"bytes"}]}, 0) as TicketToken; - tokenTicketChainId = createToken({"prim":"ticket","args":[{"prim":"chain_id"}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketInt = createToken({"prim":"ticket","args":[{"prim":"int"}]}, 0) as TicketToken; - tokenTicketKey = createToken({"prim":"ticket","args":[{"prim":"key"}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketKeyHash = createToken({"prim":"ticket","args":[{"prim":"key_hash"}]}, 0) as TicketToken; - tokenTicketMutez = createToken({"prim":"ticket","args":[{"prim":"mutez"}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketOption = createToken({"prim":"ticket","args":[{"prim":"option","args":[{"prim":"address"}],"annots":["%setApprover"]}]}, 0) as TicketToken; - tokenTicketOr = createToken({"prim":"ticket","args":[{"prim":"or","args":[{"prim":"nat"},{"prim":"string"}]}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketPair = createToken({"prim":"ticket","args":[{"prim":"pair","args":[{"prim":"nat"},{"prim":"string"}]}]}, 0) as TicketToken; - tokenTicketSignature = createToken({"prim":"ticket","args":[{"prim":"signature"}],"annots":["%test"]}, 0) as TicketToken; - tokenTicketString = createToken({"prim":"ticket","args":[{"prim":"string"}]}, 0) as TicketToken; - tokenTicketUnit = createToken({"prim":"ticket","args":[{"prim":"unit"}],"annots":["%test"]}, 0) as TicketToken; + tokenTicketNat = createToken({ "prim": "ticket", "args": [{ "prim": "nat" }], "annots": ["%receive"] }, 0) as TicketToken; + tokenTicketTimestamp = createToken({ "prim": "ticket", "args": [{ "prim": "timestamp" }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketAddress = createToken({ "prim": "ticket", "args": [{ "prim": "address" }] }, 0) as TicketToken; + tokenTicketBool = createToken({ "prim": "ticket", "args": [{ "prim": "bool" }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketBytes = createToken({ "prim": "ticket", "args": [{ "prim": "bytes" }] }, 0) as TicketToken; + tokenTicketChainId = createToken({ "prim": "ticket", "args": [{ "prim": "chain_id" }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketInt = createToken({ "prim": "ticket", "args": [{ "prim": "int" }] }, 0) as TicketToken; + tokenTicketKey = createToken({ "prim": "ticket", "args": [{ "prim": "key" }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketKeyHash = createToken({ "prim": "ticket", "args": [{ "prim": "key_hash" }] }, 0) as TicketToken; + tokenTicketMutez = createToken({ "prim": "ticket", "args": [{ "prim": "mutez" }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketOption = createToken({ "prim": "ticket", "args": [{ "prim": "option", "args": [{ "prim": "address" }], "annots": ["%setApprover"] }] }, 0) as TicketToken; + tokenTicketOr = createToken({ "prim": "ticket", "args": [{ "prim": "or", "args": [{ "prim": "nat" }, { "prim": "string" }] }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketPair = createToken({ "prim": "ticket", "args": [{ "prim": "pair", "args": [{ "prim": "nat" }, { "prim": "string" }] }] }, 0) as TicketToken; + tokenTicketSignature = createToken({ "prim": "ticket", "args": [{ "prim": "signature" }], "annots": ["%test"] }, 0) as TicketToken; + tokenTicketString = createToken({ "prim": "ticket", "args": [{ "prim": "string" }] }, 0) as TicketToken; + tokenTicketUnit = createToken({ "prim": "ticket", "args": [{ "prim": "unit" }], "annots": ["%test"] }, 0) as TicketToken; }); describe('EncodeObject', () => { @@ -60,7 +60,7 @@ describe('Ticket token', () => { expect(() => tokenTicketOption.EncodeObject('tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu')).toThrowError(EncodeTicketError); expect(() => tokenTicketOption.EncodeObject(null)).toThrowError(EncodeTicketError); expect(() => tokenTicketOr.EncodeObject('string')).toThrowError(EncodeTicketError); - expect(() => tokenTicketPair.EncodeObject({0: 0, 1: 'string'})).toThrowError(EncodeTicketError); + expect(() => tokenTicketPair.EncodeObject({ 0: 0, 1: 'string' })).toThrowError(EncodeTicketError); expect(() => tokenTicketSignature.EncodeObject('edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg')).toThrowError(EncodeTicketError); expect(() => tokenTicketString.EncodeObject('hello')).toThrowError(EncodeTicketError); expect(() => tokenTicketUnit.EncodeObject('Unit')).toThrowError(EncodeTicketError); @@ -95,7 +95,7 @@ describe('Ticket token', () => { describe('Execute', () => { it('Should execute on readTicketType with ticket of type nat', () => { - expect(tokenTicketNat.Execute({"prim":"Pair","args":[{"string":"KT1EAMUQC1yJ2sRPNPpLHVMGCzroYGe1C1ea"},{"int":"0"},{"int":"1"}]})).toEqual({ + expect(tokenTicketNat.Execute({ "prim": "Pair", "args": [{ "string": "KT1EAMUQC1yJ2sRPNPpLHVMGCzroYGe1C1ea" }, { "int": "0" }, { "int": "1" }] })).toEqual({ ticketer: 'KT1EAMUQC1yJ2sRPNPpLHVMGCzroYGe1C1ea', value: new BigNumber('0'), amount: new BigNumber('1') @@ -103,7 +103,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type timestamp', () => { - expect(tokenTicketTimestamp.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"2021-03-09T16:32:15Z"},{"int":"2"}]})).toEqual({ + expect(tokenTicketTimestamp.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "2021-03-09T16:32:15Z" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: "2021-03-09T16:32:15.000Z", amount: new BigNumber('2') @@ -111,7 +111,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type address', () => { - expect(tokenTicketAddress.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu"},{"int":"2"}]})).toEqual({ + expect(tokenTicketAddress.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: "tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu", amount: new BigNumber('2') @@ -119,7 +119,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type bool', () => { - expect(tokenTicketBool.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"prim":"True"},{"int":"2"}]})).toEqual({ + expect(tokenTicketBool.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "prim": "True" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: true, amount: new BigNumber('2') @@ -127,7 +127,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type bytes', () => { - expect(tokenTicketBytes.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"bytes":"CAFE"},{"int":"2"}]})).toEqual({ + expect(tokenTicketBytes.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "bytes": "CAFE" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'CAFE', amount: new BigNumber('2') @@ -135,7 +135,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type chainId', () => { - expect(tokenTicketChainId.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"NetXSgo1ZT2DRUG"},{"int":"2"}]})).toEqual({ + expect(tokenTicketChainId.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "NetXSgo1ZT2DRUG" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'NetXSgo1ZT2DRUG', amount: new BigNumber('2') @@ -143,7 +143,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type int', () => { - expect(tokenTicketInt.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"int":"25"},{"int":"2"}]})).toEqual({ + expect(tokenTicketInt.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "int": "25" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: new BigNumber(25), amount: new BigNumber('2') @@ -151,7 +151,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type key', () => { - expect(tokenTicketKey.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"edpkuRkcStobJ569XFxmE6edyRQQzMmtf4ZnmPkTPfSQnt6P3Nym2V"},{"int":"2"}]})).toEqual({ + expect(tokenTicketKey.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "edpkuRkcStobJ569XFxmE6edyRQQzMmtf4ZnmPkTPfSQnt6P3Nym2V" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'edpkuRkcStobJ569XFxmE6edyRQQzMmtf4ZnmPkTPfSQnt6P3Nym2V', amount: new BigNumber('2') @@ -159,7 +159,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type keyHash', () => { - expect(tokenTicketKeyHash.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu"},{"int":"2"}]})).toEqual({ + expect(tokenTicketKeyHash.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: new BigNumber('2') @@ -167,7 +167,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type mutez', () => { - expect(tokenTicketMutez.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"int":"1000000"},{"int":"2"}]})).toEqual({ + expect(tokenTicketMutez.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "int": "1000000" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: new BigNumber('1000000'), amount: new BigNumber('2') @@ -175,15 +175,15 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type option', () => { - expect(tokenTicketOption.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"prim":'Some',"args":[{"string":"tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu"}]},{"int":"2"}]})).toEqual({ + expect(tokenTicketOption.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "prim": 'Some', "args": [{ "string": "tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu" }] }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu', amount: new BigNumber('2') }); - }); + }); it('Should execute on readTicketType with ticket of type option when value is null', () => { - expect(tokenTicketOption.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"prim":"None"},{"int":"2"}]})).toEqual({ + expect(tokenTicketOption.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "prim": "None" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: null, amount: new BigNumber('2') @@ -191,23 +191,23 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type or with right value', () => { - expect(tokenTicketOr.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"prim":"Right","args":[{"string":"Hello"}]},{"int":"2"}]})).toEqual({ + expect(tokenTicketOr.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "prim": "Right", "args": [{ "string": "Hello" }] }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', - value: {1: 'Hello'}, + value: { 1: 'Hello' }, amount: new BigNumber('2') }); }); it('Should execute on readTicketType with ticket of type pair', () => { - expect(tokenTicketPair.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"prim":"Pair","args":[{"int":"7"},{"string":"hello"}]},{"int":"2"}]})).toEqual({ + expect(tokenTicketPair.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "prim": "Pair", "args": [{ "int": "7" }, { "string": "hello" }] }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', - value: {0: new BigNumber('7') , 1: 'hello'}, + value: { 0: new BigNumber('7'), 1: 'hello' }, amount: new BigNumber('2') }); }); it('Should execute on readTicketType with ticket of type signature', () => { - expect(tokenTicketSignature.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg"},{"int":"2"}]})).toEqual({ + expect(tokenTicketSignature.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg', amount: new BigNumber('2') @@ -215,7 +215,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type string', () => { - expect(tokenTicketString.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"test"},{"int":"2"}]})).toEqual({ + expect(tokenTicketString.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "test" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: 'test', amount: new BigNumber('2') @@ -223,7 +223,7 @@ describe('Ticket token', () => { }); it('Should execute on readTicketType with ticket of type unit', () => { - expect(tokenTicketUnit.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"prim":"Unit"},{"int":"2"}]})).toEqual({ + expect(tokenTicketUnit.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "prim": "Unit" }, { "int": "2" }] })).toEqual({ ticketer: 'KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw', value: UnitValue, amount: new BigNumber('2') @@ -232,9 +232,9 @@ describe('Ticket token', () => { }); describe('Ticket with custom semantic', () => { - it('Should use custom semantic when provided', () => { - const result = tokenTicketString.Execute({"prim":"Pair","args":[{"string":"KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw"},{"string":"test"},{"int":"2"}]}, { ticket: () => 'working' }); - expect(result).toBe('working'); + it('Should use custom semantic when provided', () => { + const result = tokenTicketString.Execute({ "prim": "Pair", "args": [{ "string": "KT1PVuv7af4VkPsZVZ8oZz9GSSdGnGBCbFWw" }, { "string": "test" }, { "int": "2" }] }, { ticket: () => 'working' }); + expect(result).toBe('working'); }); }); @@ -247,6 +247,24 @@ describe('Ticket token', () => { value: 'string', amount: 'int' }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'ticket', + schema: { + ticketer: { + __michelsonType: 'contract', + schema: 'contract' + }, + value: { + __michelsonType: 'string', + schema: 'string' + }, + amount: { + __michelsonType: 'int', + schema: 'int' + } + } + }); }); }); }); diff --git a/packages/taquito-michelson-encoder/test/tokens/timestamp.spec.ts b/packages/taquito-michelson-encoder/test/tokens/timestamp.spec.ts index fb62e3ebcf..8cefc042bb 100644 --- a/packages/taquito-michelson-encoder/test/tokens/timestamp.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/timestamp.spec.ts @@ -36,4 +36,13 @@ describe('Timestamp token', () => { expect(token.Encode(['2021-12-03T21:21:10.000Z'])).toEqual({ string: '2021-12-03T21:21:10.000Z' }); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'timestamp', + schema: 'timestamp' + }); + }); + }); }); \ No newline at end of file diff --git a/packages/taquito-michelson-encoder/test/tokens/unit.spec.ts b/packages/taquito-michelson-encoder/test/tokens/unit.spec.ts index aff10b36f5..de7f2a6094 100644 --- a/packages/taquito-michelson-encoder/test/tokens/unit.spec.ts +++ b/packages/taquito-michelson-encoder/test/tokens/unit.spec.ts @@ -33,4 +33,13 @@ describe('Signature token', () => { expect(token.compare(UnitValue, UnitValue)).toEqual(0); }); }); + + describe('generateSchema', () => { + it('Should generate the schema properly', () => { + expect(token.generateSchema()).toEqual({ + __michelsonType: 'unit', + schema: 'unit' + }); + }); + }); }); diff --git a/packages/taquito-michelson-encoder/test/vote_contract.spec.ts b/packages/taquito-michelson-encoder/test/vote_contract.spec.ts index 59e63dc566..3071abeb02 100644 --- a/packages/taquito-michelson-encoder/test/vote_contract.spec.ts +++ b/packages/taquito-michelson-encoder/test/vote_contract.spec.ts @@ -14,6 +14,44 @@ describe('Schema test', () => { key: 'key_hash', }, }); + + expect(schema.generateSchema()).toEqual({ + __michelsonType: 'pair', + schema: { + mgr1: { + __michelsonType: 'pair', + schema: { + addr: { + __michelsonType: "address", + schema: "address" + }, + key: { + "__michelsonType": "option", + "schema": { + __michelsonType: "key_hash", + schema: "key_hash" + } + }, + } + }, + mgr2: { + __michelsonType: 'pair', + schema: { + addr: { + __michelsonType: "address", + schema: "address" + }, + key: { + "__michelsonType": "option", + "schema": { + __michelsonType: "key_hash", + schema: "key_hash" + } + }, + } + }, + } + }); }); it('Should parse storage properly', () => {