Repository: ecadlabs/taquito
Pull request #1008 (2021-08-10 16:29:57)

Issue-970 Added test cases and changes for ticket schema
Thank you for your contribution to Taquito.

Before submitting this PR, please make sure:

- [ ] Your code builds cleanly without any errors or warnings
- [ ] You have added unit tests
- [ ] You have added integration tests (if relevant/appropriate)
- [ ] All public methods or types have TypeDoc coverage with a complete description, and ideally an @example
- [ ] You have added or updated corresponding documentation
- [ ] If relevant, you have written a first draft summary describing the change for inclusion in Release Notes. 

## Release Note Draft Snippet

__If relevant, please write a summary of your change that will be suitable for
inclusion in the Release Notes for the next Taquito release.__


github-actions[bot]: A new deploy preview is available on Netlify at https://ad1aafa3--tezostaquito.netlify.app
github-actions[bot]: New packages have been deployed to the preview repository at https://npm.preview.tezostaquito.io/.

### Published packages:
```
npm i @taquito/rpc@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-signer@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/http-utils@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/signer@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/beacon-wallet@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/remote-signer@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/local-forging@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/ledger-signer@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip16@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/utils@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tzip12@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michel-codec@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/tezbridge-wallet@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/michelson-encoder@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
npm i @taquito/taquito@10.0.0-ad1aafa3--1008 --registry https://npm.preview.tezostaquito.io/
```
codecov-commenter: # [Codecov](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) Report
> Merging [#1008](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) (0b24bbb) into [master](https://codecov.io/gh/ecadlabs/taquito/commit/ad1b2ec2393e789d72e782f741d4470e45986c64?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) (ad1b2ec) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/ecadlabs/taquito/pull/1008/graphs/tree.svg?width=650&height=150&src=pr&token=wXiK0M3HfY&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs)](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs)

```diff
@@           Coverage Diff           @@
##           master    #1008   +/-   ##
=======================================
  Coverage   81.08%   81.09%           
=======================================
  Files         164      164           
  Lines        8926     8929    +3     
  Branches     2256     2258    +2     
=======================================
+ Hits         7238     7241    +3     
  Misses       1681     1681           
  Partials        7        7           
```


| [Impacted Files](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs) | Coverage Δ | |
|---|---|---|
| [...ges/taquito-michelson-encoder/src/tokens/ticket.ts](https://codecov.io/gh/ecadlabs/taquito/pull/1008/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs#diff-cGFja2FnZXMvdGFxdWl0by1taWNoZWxzb24tZW5jb2Rlci9zcmMvdG9rZW5zL3RpY2tldC50cw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs). Last update [ad1b2ec...0b24bbb](https://codecov.io/gh/ecadlabs/taquito/pull/1008?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecadlabs).


Patch:
diff --git a/packages/taquito-michelson-encoder/src/tokens/ticket.ts b/packages/taquito-michelson-encoder/src/tokens/ticket.ts
index efef8c468..f66a7b206 100644
--- a/packages/taquito-michelson-encoder/src/tokens/ticket.ts
+++ b/packages/taquito-michelson-encoder/src/tokens/ticket.ts
@@ -36,6 +36,16 @@ export class TicketToken extends Token {
     const ticketer = this.createToken(ticketerType, this.idx);
     const value = this.createToken(this.val.args[0], this.idx);
     const amount = this.createToken(amountType, this.idx);
+
+    if(undefined == val.args[2] &&
+       undefined !== val.args[1].args) {
+      return {
+            ticketer: ticketer.Execute(val.args[0], semantics),
+            value: value.Execute(val.args[1].args[0], semantics),
+            amount: amount.Execute(val.args[1].args[1], semantics)
+      }
+    }
+
     return {
       ticketer: ticketer.Execute(val.args[0], semantics),
       value: value.Execute(val.args[1], semantics),


Test patch:
diff --git a/packages/taquito-michelson-encoder/test/sample22.spec.ts b/packages/taquito-michelson-encoder/test/sample22.spec.ts
new file mode 100644
index 000000000..3930ca007
--- /dev/null
+++ b/packages/taquito-michelson-encoder/test/sample22.spec.ts
@@ -0,0 +1,27 @@
+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'] },
+                ],
+            },
+        ],
+    };
+    const schema = new Schema(storageType);
+
+    expect(schema.ExtractSchema()).toEqual({
+        list: {
+        "from": "address",
+        "to": "address"
+      }
+    });
+
+  });
+});
\ No newline at end of file
diff --git a/packages/taquito-michelson-encoder/test/sample23_complex_ticket.spec.ts b/packages/taquito-michelson-encoder/test/sample23_complex_ticket.spec.ts
new file mode 100644
index 000000000..b52e7144e
--- /dev/null
+++ b/packages/taquito-michelson-encoder/test/sample23_complex_ticket.spec.ts
@@ -0,0 +1,29 @@
+import BigNumber from 'bignumber.js';
+import { Schema } from '../src/schema/storage';
+
+describe('Ticket token type structure', () => {
+  it('Should extract correct schema for token type ticket', () => {
+    const schema = new Schema({
+        prim: 'big_map',
+        args: [{ prim: 'nat' }, { prim: 'ticket', args: [{ prim: 'nat' }] }],
+        annots: ['%tickets']
+    });
+
+    const value = schema.ExecuteOnBigMapValue({
+        prim: 'Pair',
+        args: [
+            { string: 'KT1EAMUQC1yJ2sRPNPpLHVMGCzroYGe1C1ea' },
+            {
+                prim: 'Pair',
+                args: [{ int: '0' }, { int: '1' }],
+            },
+        ],
+    });
+    expect(value).toEqual({
+        ticketer: 'KT1EAMUQC1yJ2sRPNPpLHVMGCzroYGe1C1ea',
+        value: new BigNumber('0'),
+        amount: new BigNumber('1')
+    });
+
+  });
+});
\ No newline at end of file