diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000000..304353b12e --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,7 @@ +module.exports = { + endOfLine: 'lf', + semi: true, + singleQuote: true, + tabWidth: 2, + trailingComma: 'es5', +}; diff --git a/packages/tezos-ts-michelson-encoder/src/encoding.ts b/packages/tezos-ts-michelson-encoder/src/encoding.ts index cd784141f4..2338b8d90d 100644 --- a/packages/tezos-ts-michelson-encoder/src/encoding.ts +++ b/packages/tezos-ts-michelson-encoder/src/encoding.ts @@ -1,7 +1,7 @@ -import { Buffer } from "buffer"; -const bs58check = require("bs58check"); +import { Buffer } from 'buffer'; +const bs58check = require('bs58check'); export function b58cencode(payload: string, prefix: Uint8Array) { - const payloadAr = Uint8Array.from(Buffer.from(payload, "hex")); + const payloadAr = Uint8Array.from(Buffer.from(payload, 'hex')); const n = new Uint8Array(prefix.length + payloadAr.length); n.set(prefix); @@ -17,16 +17,16 @@ export function b58decode(payload: string) { const hexParts = [] as any[]; for (let i = 0; i < byteArray.length; i++) { let hex = byteArray[i].toString(16); - let paddedHex = ("00" + hex).slice(-2); + let paddedHex = ('00' + hex).slice(-2); hexParts.push(paddedHex); } - return hexParts.join(""); + return hexParts.join(''); }; const prefix = { - [new Uint8Array([6, 161, 159]).toString()]: "0000", - [new Uint8Array([6, 161, 161]).toString()]: "0001", - [new Uint8Array([6, 161, 164]).toString()]: "0002" + [new Uint8Array([6, 161, 159]).toString()]: '0000', + [new Uint8Array([6, 161, 161]).toString()]: '0001', + [new Uint8Array([6, 161, 164]).toString()]: '0002', }; let pref = prefix[new Uint8Array(buf.slice(0, 3)).toString()]; @@ -34,16 +34,16 @@ export function b58decode(payload: string) { const hex = buf2hex(buf.slice(3)); return pref + hex; } else { - return "01" + buf2hex(buf.slice(3, 42)) + "00"; + return '01' + buf2hex(buf.slice(3, 42)) + '00'; } } export function encodePubKey(value: string) { - if (value.substring(0, 2) === "00") { + if (value.substring(0, 2) === '00') { const prefix: { [key: string]: Uint8Array } = { - "0000": new Uint8Array([6, 161, 159]), - "0001": new Uint8Array([6, 161, 161]), - "0002": new Uint8Array([6, 161, 164]) + '0000': new Uint8Array([6, 161, 159]), + '0001': new Uint8Array([6, 161, 161]), + '0002': new Uint8Array([6, 161, 164]), }; return b58cencode(value.substring(4), prefix[value.substring(0, 4)]); diff --git a/packages/tezos-ts-michelson-encoder/src/schema/parameter.ts b/packages/tezos-ts-michelson-encoder/src/schema/parameter.ts index 4be8629a30..d15987019f 100644 --- a/packages/tezos-ts-michelson-encoder/src/schema/parameter.ts +++ b/packages/tezos-ts-michelson-encoder/src/schema/parameter.ts @@ -1,11 +1,11 @@ -import { createToken } from "../tokens/createToken"; -import { Token } from "../tokens/token"; +import { createToken } from '../tokens/createToken'; +import { Token } from '../tokens/token'; export class ParameterSchema { private root: Token; static fromRPCResponse(val: any) { - return new ParameterSchema(val.script.code.find((x: any) => x.prim === "parameter")!.args[0]); + return new ParameterSchema(val.script.code.find((x: any) => x.prim === 'parameter')!.args[0]); } constructor(val: any) { diff --git a/packages/tezos-ts-michelson-encoder/src/schema/storage.ts b/packages/tezos-ts-michelson-encoder/src/schema/storage.ts index 8a847be621..a2de8fbd21 100644 --- a/packages/tezos-ts-michelson-encoder/src/schema/storage.ts +++ b/packages/tezos-ts-michelson-encoder/src/schema/storage.ts @@ -1,23 +1,23 @@ -import { Token } from "../tokens/token"; +import { Token } from '../tokens/token'; -import { BigMapToken } from "../tokens/bigmap"; +import { BigMapToken } from '../tokens/bigmap'; -import { createToken } from "../tokens/createToken"; +import { createToken } from '../tokens/createToken'; -import { RpcTransaction } from "./model"; +import { RpcTransaction } from './model'; export class Schema { private root: Token; private bigMap?: BigMapToken; static fromRPCResponse(val: any) { - return new Schema(val.script.code.find((x: any) => x.prim === "storage")!.args[0]); + return new Schema(val.script.code.find((x: any) => x.prim === 'storage')!.args[0]); } constructor(val: any) { this.root = createToken(val, 0); - if (val.prim === "pair" && val.args[0].prim === "big_map") { + if (val.prim === 'pair' && val.args[0].prim === 'big_map') { this.bigMap = new BigMapToken(val.args[0], 0, createToken); } } @@ -28,7 +28,7 @@ export class Schema { ExecuteOnBigMapDiff(diff: any) { if (!this.bigMap) { - throw new Error("No big map schema"); + throw new Error('No big map schema'); } return this.bigMap.Execute(diff); @@ -36,7 +36,7 @@ export class Schema { ExecuteOnBigMapValue(key: any) { if (!this.bigMap) { - throw new Error("No big map schema"); + throw new Error('No big map schema'); } return this.bigMap.ValueSchema.Execute(key); @@ -44,7 +44,7 @@ export class Schema { EncodeBigMapKey(key: string) { if (!this.bigMap) { - throw new Error("No big map schema"); + throw new Error('No big map schema'); } return this.bigMap.KeySchema.ToBigMapKey(key); @@ -56,19 +56,19 @@ export class Schema { ComputeState(tx: RpcTransaction[], state: any) { if (!this.bigMap) { - throw new Error("No big map schema"); + throw new Error('No big map schema'); } const bigMap = tx.reduce((prev, current) => { return { ...prev, - ...this.ExecuteOnBigMapDiff(current.contents[0].metadata.operation_result.big_map_diff) + ...this.ExecuteOnBigMapDiff(current.contents[0].metadata.operation_result.big_map_diff), }; }, {}); return { ...this.Execute(state), - [this.bigMap.annot]: bigMap + [this.bigMap.annot]: bigMap, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tezos-ts-michelson-encoder.ts b/packages/tezos-ts-michelson-encoder/src/tezos-ts-michelson-encoder.ts index b51829054d..f8fea506e7 100644 --- a/packages/tezos-ts-michelson-encoder/src/tezos-ts-michelson-encoder.ts +++ b/packages/tezos-ts-michelson-encoder/src/tezos-ts-michelson-encoder.ts @@ -1,2 +1,2 @@ -export * from "./schema/storage"; -export * from "./schema/parameter"; +export * from './schema/storage'; +export * from './schema/parameter'; diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/bigmap.ts b/packages/tezos-ts-michelson-encoder/src/tokens/bigmap.ts index 5b32231da1..9728d9545e 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/bigmap.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/bigmap.ts @@ -1,8 +1,8 @@ -import { Token, TokenFactory, ComparableToken } from "./token"; -import { encodePubKey } from "../encoding"; +import { Token, TokenFactory, ComparableToken } from './token'; +import { encodePubKey } from '../encoding'; export class BigMapToken extends Token { - static prim = "big_map"; + static prim = 'big_map'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, protected idx: number, @@ -21,7 +21,7 @@ export class BigMapToken extends Token { public ExtractSchema() { return { - [this.KeySchema.ExtractSchema()]: this.ValueSchema.ExtractSchema() + [this.KeySchema.ExtractSchema()]: this.ValueSchema.ExtractSchema(), }; } @@ -29,7 +29,7 @@ export class BigMapToken extends Token { return val.reduce((prev, current) => { return { ...prev, - [encodePubKey(current.key.bytes)]: this.ValueSchema.Execute(current.value) + [encodePubKey(current.key.bytes)]: this.ValueSchema.Execute(current.value), }; }, {}); } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/address.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/address.ts index 49031d69ec..7aa19b5014 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/address.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/address.ts @@ -1,8 +1,8 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; -import { b58decode, encodePubKey } from "../../encoding"; +import { Token, TokenFactory, ComparableToken } from '../token'; +import { b58decode, encodePubKey } from '../../encoding'; export class AddressToken extends Token implements ComparableToken { - static prim = "address"; + static prim = 'address'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -16,7 +16,7 @@ export class AddressToken extends Token implements ComparableToken { const decoded = b58decode(val); return { key: { bytes: decoded }, - type: { prim: "bytes" } + type: { prim: 'bytes' }, }; } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bool.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bool.ts index 6e652d2a57..574a4f74cb 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bool.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bool.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "../token"; +import { Token, TokenFactory } from '../token'; export class BoolToken extends Token { - static prim = "bool"; + static prim = 'bool'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bytes.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bytes.ts index 6844b4cfe7..50e3184e14 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bytes.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/bytes.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; +import { Token, TokenFactory, ComparableToken } from '../token'; export class BytesToken extends Token implements ComparableToken { - static prim = "bytes"; + static prim = 'bytes'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -14,7 +14,7 @@ export class BytesToken extends Token implements ComparableToken { public ToBigMapKey(val: string) { return { key: { bytes: val }, - type: { prim: BytesToken.prim } + type: { prim: BytesToken.prim }, }; } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/int.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/int.ts index 42369de6ee..767602b19a 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/int.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/int.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; +import { Token, TokenFactory, ComparableToken } from '../token'; export class IntToken extends Token implements ComparableToken { - static prim = "int"; + static prim = 'int'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -22,7 +22,7 @@ export class IntToken extends Token implements ComparableToken { public ToBigMapKey(val: string) { return { key: { int: val }, - type: { prim: IntToken.prim } + type: { prim: IntToken.prim }, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/mutez.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/mutez.ts index 468bf60f4c..3f7f49c10a 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/mutez.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/mutez.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; +import { Token, TokenFactory, ComparableToken } from '../token'; export class MutezToken extends Token implements ComparableToken { - static prim = "mutez"; + static prim = 'mutez'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -22,7 +22,7 @@ export class MutezToken extends Token implements ComparableToken { public ToBigMapKey(val: string) { return { key: { int: val }, - type: { prim: MutezToken.prim } + type: { prim: MutezToken.prim }, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/nat.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/nat.ts index 50f50a4ae9..9be5d10e73 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/nat.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/nat.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; +import { Token, TokenFactory, ComparableToken } from '../token'; export class NatToken extends Token implements ComparableToken { - static prim = "nat"; + static prim = 'nat'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -22,7 +22,7 @@ export class NatToken extends Token implements ComparableToken { public ToBigMapKey(val: string) { return { key: { int: val }, - type: { prim: NatToken.prim } + type: { prim: NatToken.prim }, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/string.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/string.ts index 0d05cba758..c508fba1c3 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/string.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/string.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; +import { Token, TokenFactory, ComparableToken } from '../token'; export class StringToken extends Token implements ComparableToken { - static prim = "string"; + static prim = 'string'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -27,7 +27,7 @@ export class StringToken extends Token implements ComparableToken { public ToBigMapKey(val: string) { return { key: { string: val }, - type: { prim: StringToken.prim } + type: { prim: StringToken.prim }, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/timestamp.ts b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/timestamp.ts index ebf6ffeb38..19c5d7d40f 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/comparable/timestamp.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/comparable/timestamp.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory, ComparableToken } from "../token"; +import { Token, TokenFactory, ComparableToken } from '../token'; export class TimestampToken extends Token implements ComparableToken { - static prim = "timestamp"; + static prim = 'timestamp'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -27,7 +27,7 @@ export class TimestampToken extends Token implements ComparableToken { public ToBigMapKey(val: string) { return { key: { timestamp: val }, - type: { prim: TimestampToken.prim } + type: { prim: TimestampToken.prim }, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/contract.ts b/packages/tezos-ts-michelson-encoder/src/tokens/contract.ts index 24c12bb8e6..344da83965 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/contract.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/contract.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class ContractToken extends Token { - static prim = "contract"; + static prim = 'contract'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -12,7 +12,7 @@ export class ContractToken extends Token { } public Execute() { - return ""; + return ''; } public ExtractSchema() { diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/createToken.ts b/packages/tezos-ts-michelson-encoder/src/tokens/createToken.ts index d5e55b0125..02bb016827 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/createToken.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/createToken.ts @@ -1,5 +1,5 @@ -import { tokens } from "./tokens"; -import { Token } from "./token"; +import { tokens } from './tokens'; +import { Token } from './token'; export function createToken(val: any, idx: number): Token { const t = tokens.find(x => x.prim === val.prim); diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/list.ts b/packages/tezos-ts-michelson-encoder/src/tokens/list.ts index 02e0e57f83..e2bf950fb5 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/list.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/list.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class ListToken extends Token { - static prim = "list"; + static prim = 'list'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/map.ts b/packages/tezos-ts-michelson-encoder/src/tokens/map.ts index e5e3df1019..6bb846b4c6 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/map.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/map.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class MapToken extends Token { - static prim = "map"; + static prim = 'map'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -23,14 +23,14 @@ export class MapToken extends Token { return val.reduce((prev, current) => { return { ...prev, - [this.KeySchema.ToKey(current.args[0])]: this.ValueSchema.Execute(current.args[1]) + [this.KeySchema.ToKey(current.args[0])]: this.ValueSchema.Execute(current.args[1]), }; }, {}); } public ExtractSchema() { return { - [this.KeySchema.ExtractSchema()]: this.ValueSchema.ExtractSchema() + [this.KeySchema.ExtractSchema()]: this.ValueSchema.ExtractSchema(), }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/option.ts b/packages/tezos-ts-michelson-encoder/src/tokens/option.ts index 6f13048175..66de75a072 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/option.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/option.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class OptionToken extends Token { - static prim = "option"; + static prim = 'option'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/or.ts b/packages/tezos-ts-michelson-encoder/src/tokens/or.ts index ad9de9f825..7588ee272e 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/or.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/or.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class OrToken extends Token { - static prim = "or"; + static prim = 'or'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -15,11 +15,11 @@ export class OrToken extends Token { const leftToken = this.createToken(this.val.args[0], this.idx); const rightToken = this.createToken(this.val.args[1], this.idx + 1); - if (val.prim === "Right") { + if (val.prim === 'Right') { return rightToken.Execute(val.args[0]); } else { return { - [leftToken.annot]: leftToken.Execute(val.args[0]) + [leftToken.annot]: leftToken.Execute(val.args[0]), }; } } @@ -44,7 +44,7 @@ export class OrToken extends Token { return { ...leftValue, - ...rightValue + ...rightValue, }; } } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/pair.ts b/packages/tezos-ts-michelson-encoder/src/tokens/pair.ts index bc1232e42e..17befdd82c 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/pair.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/pair.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class PairToken extends Token { - static prim = "pair"; + static prim = 'pair'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, @@ -24,7 +24,7 @@ export class PairToken extends Token { const res = { [leftToken.annot]: leftToken.Execute(val.args[0]), - ...rightValue + ...rightValue, }; return res; } @@ -42,7 +42,7 @@ export class PairToken extends Token { const res = { [leftToken.annot]: leftToken.ExtractSchema(), - ...rightValue + ...rightValue, }; return res; } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/token.ts b/packages/tezos-ts-michelson-encoder/src/tokens/token.ts index 293de16fac..77cf263e8c 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/token.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/token.ts @@ -19,7 +19,7 @@ export abstract class Token { get annot() { return (Array.isArray(this.val.annots) ? this.val.annots[0] : String(this.idx)).replace( /(%|\:)(_Liq_entry_)?/, - "" + '' ); } diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/tokens.ts b/packages/tezos-ts-michelson-encoder/src/tokens/tokens.ts index 751d28f488..09bf7cdaa6 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/tokens.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/tokens.ts @@ -1,28 +1,28 @@ -import { PairToken } from "./pair"; +import { PairToken } from './pair'; -import { NatToken } from "./comparable/nat"; +import { NatToken } from './comparable/nat'; -import { StringToken } from "./comparable/string"; +import { StringToken } from './comparable/string'; -import { BigMapToken } from "./bigmap"; +import { BigMapToken } from './bigmap'; -import { AddressToken } from "./comparable/address"; +import { AddressToken } from './comparable/address'; -import { MapToken } from "./map"; +import { MapToken } from './map'; -import { BoolToken } from "./comparable/bool"; +import { BoolToken } from './comparable/bool'; -import { OrToken } from "./or"; +import { OrToken } from './or'; -import { ContractToken } from "./contract"; +import { ContractToken } from './contract'; -import { ListToken } from "./list"; -import { MutezToken } from "./comparable/mutez"; -import { BytesToken } from "./comparable/bytes"; -import { OptionToken } from "./option"; -import { TimestampToken } from "./comparable/timestamp"; -import { IntToken } from "./comparable/int"; -import { UnitToken } from "./unit"; +import { ListToken } from './list'; +import { MutezToken } from './comparable/mutez'; +import { BytesToken } from './comparable/bytes'; +import { OptionToken } from './option'; +import { TimestampToken } from './comparable/timestamp'; +import { IntToken } from './comparable/int'; +import { UnitToken } from './unit'; export const tokens = [ PairToken, @@ -40,5 +40,5 @@ export const tokens = [ OptionToken, TimestampToken, IntToken, - UnitToken + UnitToken, ]; diff --git a/packages/tezos-ts-michelson-encoder/src/tokens/unit.ts b/packages/tezos-ts-michelson-encoder/src/tokens/unit.ts index 1093c9a233..17faf01f96 100644 --- a/packages/tezos-ts-michelson-encoder/src/tokens/unit.ts +++ b/packages/tezos-ts-michelson-encoder/src/tokens/unit.ts @@ -1,7 +1,7 @@ -import { Token, TokenFactory } from "./token"; +import { Token, TokenFactory } from './token'; export class UnitToken extends Token { - static prim = "unit"; + static prim = 'unit'; constructor( protected val: { prim: string; args: any[]; annots: any[] }, diff --git a/packages/tezos-ts-michelson-encoder/test/tezos-ts-michelson-encoder.spec.ts b/packages/tezos-ts-michelson-encoder/test/tezos-ts-michelson-encoder.spec.ts index 0fc308c87a..0d76856da7 100644 --- a/packages/tezos-ts-michelson-encoder/test/tezos-ts-michelson-encoder.spec.ts +++ b/packages/tezos-ts-michelson-encoder/test/tezos-ts-michelson-encoder.spec.ts @@ -1,232 +1,232 @@ -import { Schema, ParameterSchema } from "../src/tezos-ts-michelson-encoder"; +import { Schema, ParameterSchema } from '../src/tezos-ts-michelson-encoder'; -import { storage, rpcContractResponse, bigMapDiff, params, txParams } from "../data/sample1"; +import { storage, rpcContractResponse, bigMapDiff, params, txParams } from '../data/sample1'; -import { storage as storage2, rpcContractResponse as rpcContractResponse2 } from "../data/sample2"; +import { storage as storage2, rpcContractResponse as rpcContractResponse2 } from '../data/sample2'; -import { storage as storage3, rpcContractResponse as rpcContractResponse3 } from "../data/sample3"; +import { storage as storage3, rpcContractResponse as rpcContractResponse3 } from '../data/sample3'; import { storage as storage4, rpcContractResponse as rpcContractResponse4, - bigMapValue -} from "../data/sample4"; + bigMapValue, +} from '../data/sample4'; -import { storage as storage5, rpcContractResponse as rpcContractResponse5 } from "../data/sample5"; +import { storage as storage5, rpcContractResponse as rpcContractResponse5 } from '../data/sample5'; -describe("Schema test", () => { - it("Should extract schema properly", () => { +describe('Schema test', () => { + it('Should extract schema properly', () => { const schema = new Schema(storage); const s = schema.ExtractSchema(); expect(s).toEqual({ accounts: { address: { allowances: { - address: "nat" + address: 'nat', }, - balance: "nat" - } + balance: 'nat', + }, }, - name: "string", - owner: "address", - symbol: "string", - totalSupply: "nat", - version: "nat" + name: 'string', + owner: 'address', + symbol: 'string', + totalSupply: 'nat', + version: 'nat', }); }); - it("Should parse storage properly", () => { + it('Should parse storage properly', () => { const schema = new Schema(storage); const s = schema.Execute(rpcContractResponse.script.storage); expect(s).toEqual({ accounts: {}, - name: "Token B", - owner: "tz1ccqAEwfPgeoipnXtjAv1iucrpQv3DFmmS", - symbol: "B", - totalSupply: "1000", - version: "1" + name: 'Token B', + owner: 'tz1ccqAEwfPgeoipnXtjAv1iucrpQv3DFmmS', + symbol: 'B', + totalSupply: '1000', + version: '1', }); }); - it("Should parse storage with map that have string as key properly", () => { + it('Should parse storage with map that have string as key properly', () => { const schema = new Schema(storage2); const s = schema.Execute(rpcContractResponse2.script.storage); expect(s).toEqual({ - "0": {}, - "1": { - admin: "tz1M9CMEtsXm3QxA7FmMU2Qh7xzsuGXVbcDr", + '0': {}, + '1': { + admin: 'tz1M9CMEtsXm3QxA7FmMU2Qh7xzsuGXVbcDr', metaData: { - By: "https://SmartPy.io", - Help: "Use Build to define a new game board and Play to make moves", - "Play at": - "https://smartpy.io/demo/explore.html?address=KT1UvfyLytrt71jh63YV4Yex5SmbNXpWHxtg", - "SmartPy Template": "https://smartpy.io/demo/index.html?template=tictactoeFactory.py" - } + By: 'https://SmartPy.io', + Help: 'Use Build to define a new game board and Play to make moves', + 'Play at': + 'https://smartpy.io/demo/explore.html?address=KT1UvfyLytrt71jh63YV4Yex5SmbNXpWHxtg', + 'SmartPy Template': 'https://smartpy.io/demo/index.html?template=tictactoeFactory.py', + }, }, - paused: "False" + paused: 'False', }); }); - it("Should parse storage with mutez properly", () => { + it('Should parse storage with mutez properly', () => { const schema = new Schema(storage3); const s = schema.Execute(rpcContractResponse3.script.storage); expect(s).toEqual({ balances: { - KT18oQnGxZNPST7GndCN1w5o3RjCKMPRuQYb: "0", - KT1BPE6waJrv3CagjRYwtfF3ZbE4nKxCa35Q: "79540178", - KT1BgkG1u8oQ5x1nySJq9TSExZYZvuUHxG4d: "94738111", - KT1CDEg2oY3VfMa1neB7hK5LoVMButvivKYv: "972668", - KT1CSecsvPEUbnjQ58UAStVvanN2CghEuDNr: "850791", - KT1ETj1iC48XWpa7fGhD9AAArZgLkgNrk35W: "6694159084", - KT1F7Gn9YupQLwU4qM8u9CgcRzBa3gDRd1e5: "2244700000", - KT1GtaRfTTHXTYVNGZFsZjoB9T2yn3bToZEs: "67923763011", - KT1GvYJfGNqrLtUCPc4JithuXco72sxa9Ewh: "6067881716", - KT1J7u8E5XDz5LWQTr1ZKY7coDYNMh2vwvwX: "702521", - KT1KRzRDQxbGZDobSCdyWCnB6nShX3MvFLAW: "47371547783", - KT1LuVQUALxtVMnNTa36SDVwtDmpNbosZEh8: "50694800896", - KT1NkYSVn7FqXGqyi9ruiqHS7mjUzDyv6fmc: "5938869113", - KT1QB4Tib11b8gYrC77Xs9bXU8TGJTXPAK7J: "60414680184", - KT1QX5woZXV5N6iqFFHkrgZrwH9uhh7Ma6qz: "3977008911", - KT1RJ2HjvmGcrDqpPoFwy6uVDk9uf71iv7dF: "11416957072", - KT1SE8DxcSsfA7upZtdpcZGGRRP3guqSk4nM: "2155481887", - KT1SGQmwvK5s49ovZLXxLbW8RzNB1vSbtE5b: "3902114120", - KT1VqoJ5jEAY1UEugRFiSTXhTVXAsj65tsUv: "8992531001", - KT1Vqq4nD2Mgwz4bYZVFbjKUESAmxrVFfRAr: "99496052", - KT1VvGrrdJmVTwRER39btAXC64b56sLqbXkY: "9879704715", - KT1XBbG1xtdsSWDsy5dwqXpUQEEgLPm6RGRb: "482601406", - tz1LBAWdvnHjqxNNyYJhy9eBcaj3mE3cjhNQ: "700000000", - tz1LWXJ1rZKCBeQzqtPriNiFpKU5gWo2u8zT: "11220754689", - tz1NNf9KDcPa6iSi64gy1na5msfjcv3XWJs2: "37742509148", - tz1QXuUweuLrxC3LmDMoPxmpT19ijhPTc1bt: "9967227", - tz1R6ZvSYDHYCqeK3NckyjN9z1H5rHVc1xr9: "20856441766", - tz1S6yEw9hZKcNkWnoVnyjQ5Qfakt3kdYLE9: "0", - tz1TowqAmCuYzkeZ98xyacN2SnKnzJM6ssVE: "26757313041", - tz1VLcYgQsvarbcWCPfUw1Fcz27jVrB2zYBr: "995650005", - tz1WTcM46fg6fN5fdbhz1LgX2GbqyKTczzR7: "1043871972", - tz1WzAsDfPhpTA75h37pCbN2jC9JPYyhUuc2: "21165644772", - tz1amzJBBjgMaUfpEoX4npYQuXqdb4fvuBpr: "14268243108", - tz1b22ii76LksTJm7JTi6wtCYEXFa82FdwaH: "4193732", - tz1bPGEnW2wGjpyceJdUSpDHFShGddPysAHE: "49644981635", - tz1bxHfbJyEFaHzeiCfpmtwUoGtLE6VT94HC: "5581647542", - tz1cf4tBruBKA7keMHiHqivsz4oDcBBGSVDm: "1902576", - tz1cxjPRxvdYoLCUzfcJthAkdnTAunA2Dm5U: "8417961239", - tz1d8x5yMzMQRVjpuSZUUBgJtqRGMzbunvQP: "17437358995", - tz1eDP1gCVMZkukT4dxetSJMZJHmkTMBY2mL: "2498000000", - tz1eSmgHg4Xoy2RJy2owdjGsYzj5eKxaoKYr: "35524185304", - tz1ee26q3xzbsZF4AMkzysR8CxK8eZiLRzKF: "48718359", - tz1i8p76UJXw2WJt2o2puAbrt2c36DohjuzW: "123799839" + KT18oQnGxZNPST7GndCN1w5o3RjCKMPRuQYb: '0', + KT1BPE6waJrv3CagjRYwtfF3ZbE4nKxCa35Q: '79540178', + KT1BgkG1u8oQ5x1nySJq9TSExZYZvuUHxG4d: '94738111', + KT1CDEg2oY3VfMa1neB7hK5LoVMButvivKYv: '972668', + KT1CSecsvPEUbnjQ58UAStVvanN2CghEuDNr: '850791', + KT1ETj1iC48XWpa7fGhD9AAArZgLkgNrk35W: '6694159084', + KT1F7Gn9YupQLwU4qM8u9CgcRzBa3gDRd1e5: '2244700000', + KT1GtaRfTTHXTYVNGZFsZjoB9T2yn3bToZEs: '67923763011', + KT1GvYJfGNqrLtUCPc4JithuXco72sxa9Ewh: '6067881716', + KT1J7u8E5XDz5LWQTr1ZKY7coDYNMh2vwvwX: '702521', + KT1KRzRDQxbGZDobSCdyWCnB6nShX3MvFLAW: '47371547783', + KT1LuVQUALxtVMnNTa36SDVwtDmpNbosZEh8: '50694800896', + KT1NkYSVn7FqXGqyi9ruiqHS7mjUzDyv6fmc: '5938869113', + KT1QB4Tib11b8gYrC77Xs9bXU8TGJTXPAK7J: '60414680184', + KT1QX5woZXV5N6iqFFHkrgZrwH9uhh7Ma6qz: '3977008911', + KT1RJ2HjvmGcrDqpPoFwy6uVDk9uf71iv7dF: '11416957072', + KT1SE8DxcSsfA7upZtdpcZGGRRP3guqSk4nM: '2155481887', + KT1SGQmwvK5s49ovZLXxLbW8RzNB1vSbtE5b: '3902114120', + KT1VqoJ5jEAY1UEugRFiSTXhTVXAsj65tsUv: '8992531001', + KT1Vqq4nD2Mgwz4bYZVFbjKUESAmxrVFfRAr: '99496052', + KT1VvGrrdJmVTwRER39btAXC64b56sLqbXkY: '9879704715', + KT1XBbG1xtdsSWDsy5dwqXpUQEEgLPm6RGRb: '482601406', + tz1LBAWdvnHjqxNNyYJhy9eBcaj3mE3cjhNQ: '700000000', + tz1LWXJ1rZKCBeQzqtPriNiFpKU5gWo2u8zT: '11220754689', + tz1NNf9KDcPa6iSi64gy1na5msfjcv3XWJs2: '37742509148', + tz1QXuUweuLrxC3LmDMoPxmpT19ijhPTc1bt: '9967227', + tz1R6ZvSYDHYCqeK3NckyjN9z1H5rHVc1xr9: '20856441766', + tz1S6yEw9hZKcNkWnoVnyjQ5Qfakt3kdYLE9: '0', + tz1TowqAmCuYzkeZ98xyacN2SnKnzJM6ssVE: '26757313041', + tz1VLcYgQsvarbcWCPfUw1Fcz27jVrB2zYBr: '995650005', + tz1WTcM46fg6fN5fdbhz1LgX2GbqyKTczzR7: '1043871972', + tz1WzAsDfPhpTA75h37pCbN2jC9JPYyhUuc2: '21165644772', + tz1amzJBBjgMaUfpEoX4npYQuXqdb4fvuBpr: '14268243108', + tz1b22ii76LksTJm7JTi6wtCYEXFa82FdwaH: '4193732', + tz1bPGEnW2wGjpyceJdUSpDHFShGddPysAHE: '49644981635', + tz1bxHfbJyEFaHzeiCfpmtwUoGtLE6VT94HC: '5581647542', + tz1cf4tBruBKA7keMHiHqivsz4oDcBBGSVDm: '1902576', + tz1cxjPRxvdYoLCUzfcJthAkdnTAunA2Dm5U: '8417961239', + tz1d8x5yMzMQRVjpuSZUUBgJtqRGMzbunvQP: '17437358995', + tz1eDP1gCVMZkukT4dxetSJMZJHmkTMBY2mL: '2498000000', + tz1eSmgHg4Xoy2RJy2owdjGsYzj5eKxaoKYr: '35524185304', + tz1ee26q3xzbsZF4AMkzysR8CxK8eZiLRzKF: '48718359', + tz1i8p76UJXw2WJt2o2puAbrt2c36DohjuzW: '123799839', }, - buyPrice: "1062727", - decimals: "6", - inBaker: "570674096663", - name: "Tez-Baking Token", - owner: "tz1LBEKXaxQbd5Gtzbc1ATCwc3pppu81aWGc", - sellPrice: "1062060", - symbol: "BAKER", - totalSupply: "542476246169" + buyPrice: '1062727', + decimals: '6', + inBaker: '570674096663', + name: 'Tez-Baking Token', + owner: 'tz1LBEKXaxQbd5Gtzbc1ATCwc3pppu81aWGc', + sellPrice: '1062060', + symbol: 'BAKER', + totalSupply: '542476246169', }); }); - it("Should parse big map properly", () => { + it('Should parse big map properly', () => { const schema = new Schema(storage); const s = schema.ExecuteOnBigMapDiff(bigMapDiff); expect(s).toEqual({ tz1Ra8yQVQN4Nd7LpPQ6UT6t3bsWWqHZ9wa6: { allowances: { - tz1fPjyo55HwUAkd1xcL5vo6DGzJrkxAMpiD: "60" + tz1fPjyo55HwUAkd1xcL5vo6DGzJrkxAMpiD: '60', }, - balance: "200" - } + balance: '200', + }, }); }); - it("Should build parameter schema properly", () => { + it('Should build parameter schema properly', () => { const schema = new ParameterSchema(params); const s = schema.ExtractSchema(); expect(s).toEqual({ allowance: { - "4": "address", - "5": "address", - NatNatContract: "contract" + '4': 'address', + '5': 'address', + NatNatContract: 'contract', }, approve: { - "1": "address", - "2": "nat" + '1': 'address', + '2': 'nat', }, balanceOf: { - "3": "address", - NatContract: "contract" + '3': 'address', + NatContract: 'contract', }, createAccount: { - "5": "address", - "6": "nat" + '5': 'address', + '6': 'nat', }, - createAccounts: "list", + createAccounts: 'list', transfer: { - "0": "address", - "1": "nat" + '0': 'address', + '1': 'nat', }, transferFrom: { - "2": "address", - "3": "address", - "4": "nat" - } + '2': 'address', + '3': 'address', + '4': 'nat', + }, }); }); - it("Should parse parameter properly", () => { + it('Should parse parameter properly', () => { const schema = new ParameterSchema(params); const s = schema.Execute(txParams); expect(s).toEqual({ approve: { - "1": "tz1fPjyo55HwUAkd1xcL5vo6DGzJrkxAMpiD", - "2": "60" - } + '1': 'tz1fPjyo55HwUAkd1xcL5vo6DGzJrkxAMpiD', + '2': '60', + }, }); }); - describe("Sample4", () => { - it("Should encode key properly", () => { + describe('Sample4', () => { + it('Should encode key properly', () => { const schema = new Schema(storage4); - const encoded = schema.EncodeBigMapKey("AZEAZEJAZEJ"); + const encoded = schema.EncodeBigMapKey('AZEAZEJAZEJ'); expect(encoded).toEqual({ key: { - string: "AZEAZEJAZEJ" + string: 'AZEAZEJAZEJ', }, type: { - prim: "string" - } + prim: 'string', + }, }); }); - it("Should parse storage properly", () => { + it('Should parse storage properly', () => { const schema = new Schema(storage4); const storage = schema.Execute(rpcContractResponse4.script.storage); expect(storage).toEqual({ - "0": {}, - "1": "tz1W8qq2VPJcbXkAMxG8zwXCbtwbDPMfTRZd" + '0': {}, + '1': 'tz1W8qq2VPJcbXkAMxG8zwXCbtwbDPMfTRZd', }); }); - it("Should parse big map value properly", () => { + it('Should parse big map value properly', () => { const schema = new Schema(storage4); const value = schema.ExecuteOnBigMapValue(bigMapValue); expect(value).toEqual({ clients: [], - userRecord: ["1234567891", "123456", "123456"] + userRecord: ['1234567891', '123456', '123456'], }); }); }); - describe("Sample5", () => { - it("Should parse storage properly", () => { + describe('Sample5', () => { + it('Should parse storage properly', () => { const schema = new Schema(storage5); const storage = schema.Execute(rpcContractResponse5.script.storage); expect(storage).toEqual({ - "0": {}, - totalSupply: "1000", - approver: "tz1g3oS1UPgWFFpxrc2pEn4sgV3ky1Z6Qaz2", - centralBank: "tz1g3oS1UPgWFFpxrc2pEn4sgV3ky1Z6Qaz2" + '0': {}, + totalSupply: '1000', + approver: 'tz1g3oS1UPgWFFpxrc2pEn4sgV3ky1Z6Qaz2', + centralBank: 'tz1g3oS1UPgWFFpxrc2pEn4sgV3ky1Z6Qaz2', }); }); }); diff --git a/packages/tezos-ts-react-components/src/balance.tsx b/packages/tezos-ts-react-components/src/balance.tsx index d90f0abd52..d7bc2a3d42 100644 --- a/packages/tezos-ts-react-components/src/balance.tsx +++ b/packages/tezos-ts-react-components/src/balance.tsx @@ -17,13 +17,13 @@ export class Balance extends React.Component< this.state = { balance: null, - error: false + error: false, }; } async refreshBalance() { - // tslint:disable-next-line: deprecation try { + // tslint:disable-next-line: deprecation const balance = await this.context.tz.getBalance(this.props.address); this.setState({ balance, error: false }); } catch (ex) { diff --git a/packages/tezos-ts-rpc/src/tezos-ts-rpc.ts b/packages/tezos-ts-rpc/src/tezos-ts-rpc.ts index 15ab943350..434ac5b42e 100644 --- a/packages/tezos-ts-rpc/src/tezos-ts-rpc.ts +++ b/packages/tezos-ts-rpc/src/tezos-ts-rpc.ts @@ -1,4 +1,4 @@ -import { HttpBackend } from "./utils/http"; +import { HttpBackend } from './utils/http'; import { BalanceResponse, StorageResponse, @@ -7,18 +7,18 @@ import { BigMapKey, BigMapGetResponse, ManagerResponse, - DelegateResponse -} from "./types"; -import BigNumber from "bignumber.js"; + DelegateResponse, +} from './types'; +import BigNumber from 'bignumber.js'; -const defaultRPC = "https://tezrpc.me"; -const defaultChain = "main"; +const defaultRPC = 'https://tezrpc.me'; +const defaultChain = 'main'; interface RPCOptions { block: string; } -const defaultRPCOptions: RPCOptions = { block: "head" }; +const defaultRPCOptions: RPCOptions = { block: 'head' }; /*** * @description RpcClient allows interaction with Tezos network through an rpc node @@ -52,7 +52,7 @@ export class RpcClient { ): Promise { const balance = await this.httpBackend.createRequest({ url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}/balance`, - method: "GET" + method: 'GET', }); return new BigNumber(balance); } @@ -70,7 +70,7 @@ export class RpcClient { ): Promise { return this.httpBackend.createRequest({ url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}/storage`, - method: "GET" + method: 'GET', }); } @@ -87,7 +87,7 @@ export class RpcClient { ): Promise { return this.httpBackend.createRequest({ url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}/script`, - method: "GET" + method: 'GET', }); } @@ -104,11 +104,11 @@ export class RpcClient { ): Promise { const contractResponse = await this.httpBackend.createRequest({ url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}`, - method: "GET" + method: 'GET', }); return { ...contractResponse, - balance: new BigNumber(contractResponse.balance) + balance: new BigNumber(contractResponse.balance), }; } @@ -125,7 +125,7 @@ export class RpcClient { ): Promise { return this.httpBackend.createRequest({ url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}/manager`, - method: "GET" + method: 'GET', }); } @@ -142,7 +142,7 @@ export class RpcClient { ): Promise { return this.httpBackend.createRequest({ url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}/delegate`, - method: "GET" + method: 'GET', }); } @@ -161,7 +161,7 @@ export class RpcClient { return this.httpBackend.createRequest( { url: `${this.url}/chains/${this.chain}/blocks/${block}/context/contracts/${address}/big_map_get`, - method: "POST" + method: 'POST', }, key ); diff --git a/packages/tezos-ts-rpc/src/utils/http.ts b/packages/tezos-ts-rpc/src/utils/http.ts index acc2b4667e..98bc1c2d56 100644 --- a/packages/tezos-ts-rpc/src/utils/http.ts +++ b/packages/tezos-ts-rpc/src/utils/http.ts @@ -13,7 +13,7 @@ export interface HttpBackend { interface HttpRequestOptions { url: string; - method?: "GET" | "POST"; + method?: 'GET' | 'POST'; timeout?: number; } @@ -24,12 +24,12 @@ export class HttpBackend { private createXHR(): XMLHttpRequest { // tslint:disable: strict-type-predicates if ( - typeof process !== "undefined" && + typeof process !== 'undefined' && process.versions != null && process.versions.node != null // tslint:enable: strict-type-predicates ) { - const NodeXHR = require("xhr2-cookies").XMLHttpRequest; + const NodeXHR = require('xhr2-cookies').XMLHttpRequest; const request = new NodeXHR(); return request; } else { @@ -44,8 +44,8 @@ export class HttpBackend { createRequest({ url, method, timeout }: HttpRequestOptions, data?: {}) { return new Promise((resolve, reject) => { const request = this.createXHR(); - request.open(method || "GET", url); - request.setRequestHeader("Content-Type", "application/json"); + request.open(method || 'GET', url); + request.setRequestHeader('Content-Type', 'application/json'); request.timeout = timeout || defaultTimeout; request.onload = function() { if (this.status >= 200 && this.status < 300) { @@ -53,14 +53,14 @@ export class HttpBackend { } else { reject({ status: this.status, - statusText: request.statusText + statusText: request.statusText, }); } }; request.onerror = function() { reject({ status: this.status, - statusText: request.statusText + statusText: request.statusText, }); }; diff --git a/packages/tezos-ts-rpc/test/tezos-ts-rpc.spec.ts b/packages/tezos-ts-rpc/test/tezos-ts-rpc.spec.ts index 150eb76cd3..f950dedf49 100644 --- a/packages/tezos-ts-rpc/test/tezos-ts-rpc.spec.ts +++ b/packages/tezos-ts-rpc/test/tezos-ts-rpc.spec.ts @@ -1,10 +1,10 @@ -import { RpcClient } from "../src/tezos-ts-rpc"; -import BigNumber from "bignumber.js"; +import { RpcClient } from '../src/tezos-ts-rpc'; +import BigNumber from 'bignumber.js'; /** * RpcClient test */ -describe("RpcClient test", () => { +describe('RpcClient test', () => { let client: RpcClient; let httpBackend: { createRequest: jest.Mock; @@ -12,109 +12,109 @@ describe("RpcClient test", () => { beforeEach(() => { httpBackend = { - createRequest: jest.fn() + createRequest: jest.fn(), }; - client = new RpcClient("root", "test", httpBackend as any); + client = new RpcClient('root', 'test', httpBackend as any); }); - it("RpcClient is instantiable", () => { + it('RpcClient is instantiable', () => { expect(new RpcClient()).toBeInstanceOf(RpcClient); }); - describe("getBalance", () => { - it("query the right url and returns a string", async done => { - httpBackend.createRequest.mockReturnValue(Promise.resolve("10000")); - const balance = await client.getBalance("address"); + describe('getBalance', () => { + it('query the right url and returns a string', async done => { + httpBackend.createRequest.mockReturnValue(Promise.resolve('10000')); + const balance = await client.getBalance('address'); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "GET", - url: "root/chains/test/blocks/head/context/contracts/address/balance" + method: 'GET', + url: 'root/chains/test/blocks/head/context/contracts/address/balance', }); expect(balance).toBeInstanceOf(BigNumber); - expect(balance.toString()).toEqual("10000"); + expect(balance.toString()).toEqual('10000'); done(); }); }); - describe("getStorage", () => { - it("query the right url", async done => { - await client.getStorage("address"); + describe('getStorage', () => { + it('query the right url', async done => { + await client.getStorage('address'); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "GET", - url: "root/chains/test/blocks/head/context/contracts/address/storage" + method: 'GET', + url: 'root/chains/test/blocks/head/context/contracts/address/storage', }); done(); }); }); - describe("getScript", () => { - it("query the right url", async done => { - await client.getScript("address"); + describe('getScript', () => { + it('query the right url', async done => { + await client.getScript('address'); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "GET", - url: "root/chains/test/blocks/head/context/contracts/address/script" + method: 'GET', + url: 'root/chains/test/blocks/head/context/contracts/address/script', }); done(); }); }); - describe("getContract", () => { - it("query the right url", async done => { - httpBackend.createRequest.mockReturnValue(Promise.resolve({ balance: "10000" })); - const response = await client.getContract("address"); + describe('getContract', () => { + it('query the right url', async done => { + httpBackend.createRequest.mockReturnValue(Promise.resolve({ balance: '10000' })); + const response = await client.getContract('address'); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "GET", - url: "root/chains/test/blocks/head/context/contracts/address" + method: 'GET', + url: 'root/chains/test/blocks/head/context/contracts/address', }); expect(response.balance).toBeInstanceOf(BigNumber); - expect(response.balance.toString()).toEqual("10000"); + expect(response.balance.toString()).toEqual('10000'); done(); }); }); - describe("getManager", () => { - it("query the right url", async done => { - await client.getManager("address"); + describe('getManager', () => { + it('query the right url', async done => { + await client.getManager('address'); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "GET", - url: "root/chains/test/blocks/head/context/contracts/address/manager" + method: 'GET', + url: 'root/chains/test/blocks/head/context/contracts/address/manager', }); done(); }); }); - describe("getDelegate", () => { - it("query the right url", async done => { - await client.getDelegate("address"); + describe('getDelegate', () => { + it('query the right url', async done => { + await client.getDelegate('address'); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "GET", - url: "root/chains/test/blocks/head/context/contracts/address/delegate" + method: 'GET', + url: 'root/chains/test/blocks/head/context/contracts/address/delegate', }); done(); }); }); - describe("getBigMapKey", () => { - it("query the right url", async done => { - await client.getBigMapKey("address", { key: "test", type: "string" } as any); + describe('getBigMapKey', () => { + it('query the right url', async done => { + await client.getBigMapKey('address', { key: 'test', type: 'string' } as any); expect(httpBackend.createRequest.mock.calls[0][0]).toEqual({ - method: "POST", - url: "root/chains/test/blocks/head/context/contracts/address/big_map_get" + method: 'POST', + url: 'root/chains/test/blocks/head/context/contracts/address/big_map_get', }); - expect(httpBackend.createRequest.mock.calls[0][1]).toEqual({ key: "test", type: "string" }); + expect(httpBackend.createRequest.mock.calls[0][1]).toEqual({ key: 'test', type: 'string' }); done(); }); diff --git a/packages/tezos-ts/src/contract/interface.ts b/packages/tezos-ts/src/contract/interface.ts index 779cdd08d2..c08c0638fb 100644 --- a/packages/tezos-ts/src/contract/interface.ts +++ b/packages/tezos-ts/src/contract/interface.ts @@ -1,4 +1,4 @@ -import { Schema } from "@tezos-ts/michelson-encoder"; +import { Schema } from '@tezos-ts/michelson-encoder'; export type ContractSchema = Schema | unknown; diff --git a/packages/tezos-ts/src/contract/rpc-contract-provider.ts b/packages/tezos-ts/src/contract/rpc-contract-provider.ts index 67a45f1ba5..f630f9205a 100644 --- a/packages/tezos-ts/src/contract/rpc-contract-provider.ts +++ b/packages/tezos-ts/src/contract/rpc-contract-provider.ts @@ -1,6 +1,6 @@ -import { RpcClient } from "@tezos-ts/rpc"; -import { ContractProvider, ContractSchema } from "./interface"; -import { Schema } from "@tezos-ts/michelson-encoder"; +import { RpcClient } from '@tezos-ts/rpc'; +import { ContractProvider, ContractSchema } from './interface'; +import { Schema } from '@tezos-ts/michelson-encoder'; export class RpcContractProvider implements ContractProvider { constructor(private rpc: RpcClient) {} diff --git a/packages/tezos-ts/src/tezos-ts.ts b/packages/tezos-ts/src/tezos-ts.ts index ace13facdf..7813829896 100644 --- a/packages/tezos-ts/src/tezos-ts.ts +++ b/packages/tezos-ts/src/tezos-ts.ts @@ -1,8 +1,8 @@ -import { TzProvider } from "./tz/interface"; -import { RpcClient } from "@tezos-ts/rpc"; -import { ContractProvider } from "./contract/interface"; -import { RpcTzProvider } from "./tz/rpc-tz-provider"; -import { RpcContractProvider } from "./contract/rpc-contract-provider"; +import { TzProvider } from './tz/interface'; +import { RpcClient } from '@tezos-ts/rpc'; +import { ContractProvider } from './contract/interface'; +import { RpcTzProvider } from './tz/rpc-tz-provider'; +import { RpcContractProvider } from './contract/rpc-contract-provider'; /** * @description Facade class that surfaces all of the libraries capability and allow it's configuration @@ -21,7 +21,7 @@ export class TezosToolkit { * @param provider rpc url or rpcClient to use to interact with the Tezos network */ setProvider(provider: string | RpcClient) { - if (typeof provider === "string") { + if (typeof provider === 'string') { this._rpcClient = new RpcClient(provider); } else { this._rpcClient = provider; diff --git a/packages/tezos-ts/test/contract/data.ts b/packages/tezos-ts/test/contract/data.ts index 5778f20049..d57b191281 100644 --- a/packages/tezos-ts/test/contract/data.ts +++ b/packages/tezos-ts/test/contract/data.ts @@ -1,54 +1,57 @@ export const sampleStorage = { - prim: "Pair", + prim: 'Pair', args: [ [], { - prim: "Pair", + prim: 'Pair', args: [ - { string: "tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn" }, - { prim: "Pair", args: [{ prim: "False" }, { int: "200" }] } - ] - } - ] + { string: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn' }, + { prim: 'Pair', args: [{ prim: 'False' }, { int: '200' }] }, + ], + }, + ], }; export const sample = { - prim: "storage", + prim: 'storage', args: [ { - prim: "pair", + prim: 'pair', args: [ { - prim: "big_map", + prim: 'big_map', args: [ - { prim: "address" }, + { prim: 'address' }, { - prim: "pair", - args: [{ prim: "nat" }, { prim: "map", args: [{ prim: "address" }, { prim: "nat" }] }] - } - ] + prim: 'pair', + args: [ + { prim: 'nat' }, + { prim: 'map', args: [{ prim: 'address' }, { prim: 'nat' }] }, + ], + }, + ], }, { - prim: "pair", - args: [{ prim: "address" }, { prim: "pair", args: [{ prim: "bool" }, { prim: "nat" }] }] - } - ] - } - ] + prim: 'pair', + args: [{ prim: 'address' }, { prim: 'pair', args: [{ prim: 'bool' }, { prim: 'nat' }] }], + }, + ], + }, + ], }; export const sampleBigMapValue = { - prim: "Pair", + prim: 'Pair', args: [ - { int: "261" }, + { int: '261' }, [ { - prim: "Elt", - args: [{ bytes: "000035e993d8c7aaa42b5e3ccd86a33390ececc73abd" }, { int: "100" }] + prim: 'Elt', + args: [{ bytes: '000035e993d8c7aaa42b5e3ccd86a33390ececc73abd' }, { int: '100' }], }, { - prim: "Elt", - args: [{ bytes: "01c57ad825f3c2bd87ca531edd4c911598aabd3a7100" }, { int: "100" }] - } - ] - ] + prim: 'Elt', + args: [{ bytes: '01c57ad825f3c2bd87ca531edd4c911598aabd3a7100' }, { int: '100' }], + }, + ], + ], }; diff --git a/packages/tezos-ts/test/contract/rpc-contract-provider.spec.ts b/packages/tezos-ts/test/contract/rpc-contract-provider.spec.ts index 0ef292ac19..64ce7f9ae7 100644 --- a/packages/tezos-ts/test/contract/rpc-contract-provider.spec.ts +++ b/packages/tezos-ts/test/contract/rpc-contract-provider.spec.ts @@ -1,10 +1,10 @@ -import { RpcContractProvider } from "../../src/contract/rpc-contract-provider"; -import { sample, sampleStorage, sampleBigMapValue } from "./data"; +import { RpcContractProvider } from '../../src/contract/rpc-contract-provider'; +import { sample, sampleStorage, sampleBigMapValue } from './data'; /** * RPCContractProvider test */ -describe("RpcContractProvider test", () => { +describe('RpcContractProvider test', () => { let rpcContractProvider: RpcContractProvider; let mockRpcClient: { getScript: jest.Mock; @@ -16,46 +16,46 @@ describe("RpcContractProvider test", () => { mockRpcClient = { getScript: jest.fn(), getStorage: jest.fn(), - getBigMapKey: jest.fn() + getBigMapKey: jest.fn(), }; rpcContractProvider = new RpcContractProvider(mockRpcClient as any); }); - describe("getStorage", () => { - it("should call getStorage", async done => { + describe('getStorage', () => { + it('should call getStorage', async done => { mockRpcClient.getScript.mockResolvedValue({ code: [sample] }); mockRpcClient.getStorage.mockResolvedValue(sampleStorage); - const result = await rpcContractProvider.getStorage("test"); + const result = await rpcContractProvider.getStorage('test'); expect(result).toEqual({ - "0": {}, - "1": "tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn", - "2": "False", - "3": "200" + '0': {}, + '1': 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn', + '2': 'False', + '3': '200', }); done(); }); }); - describe("getBigMapKey", () => { - it("should call getBigMapKey", async done => { + describe('getBigMapKey', () => { + it('should call getBigMapKey', async done => { mockRpcClient.getScript.mockResolvedValue({ code: [sample] }); mockRpcClient.getBigMapKey.mockResolvedValue(sampleBigMapValue); const result = await rpcContractProvider.getBigMapKey( - "test", - "tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn" + 'test', + 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn' ); expect(result).toEqual({ - "0": "261", - "1": { - KT1SawqvsVdAbDzqc4KwPpaS1S1veuFgF9AN: "100", - tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn: "100" - } + '0': '261', + '1': { + KT1SawqvsVdAbDzqc4KwPpaS1S1veuFgF9AN: '100', + tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn: '100', + }, }); - expect(mockRpcClient.getBigMapKey.mock.calls[0][0]).toEqual("test"); + expect(mockRpcClient.getBigMapKey.mock.calls[0][0]).toEqual('test'); expect(mockRpcClient.getBigMapKey.mock.calls[0][1]).toEqual({ - key: { bytes: "000035e993d8c7aaa42b5e3ccd86a33390ececc73abd" }, - type: { prim: "bytes" } + key: { bytes: '000035e993d8c7aaa42b5e3ccd86a33390ececc73abd' }, + type: { prim: 'bytes' }, }); done(); }); diff --git a/packages/tezos-ts/test/tezos-ts.spec.ts b/packages/tezos-ts/test/tezos-ts.spec.ts index 1a99ba7e7c..140e971502 100644 --- a/packages/tezos-ts/test/tezos-ts.spec.ts +++ b/packages/tezos-ts/test/tezos-ts.spec.ts @@ -1,13 +1,13 @@ -import { TezosToolkit } from "../src/tezos-ts"; -import { RpcTzProvider } from "../src/tz/rpc-tz-provider"; -import { RpcContractProvider } from "../src/contract/rpc-contract-provider"; +import { TezosToolkit } from '../src/tezos-ts'; +import { RpcTzProvider } from '../src/tz/rpc-tz-provider'; +import { RpcContractProvider } from '../src/contract/rpc-contract-provider'; -describe("TezosToolkit test", () => { - it("is instantiable", () => { +describe('TezosToolkit test', () => { + it('is instantiable', () => { expect(new TezosToolkit()).toBeInstanceOf(TezosToolkit); }); - it("setProvider should change provider", () => { + it('setProvider should change provider', () => { const toolkit = new TezosToolkit(); const oldTz = toolkit.tz; @@ -17,10 +17,10 @@ describe("TezosToolkit test", () => { expect(toolkit.contract).not.toBe(oldContract); }); - it("setProvider with string should create rpc provider", () => { + it('setProvider with string should create rpc provider', () => { const toolkit = new TezosToolkit(); - toolkit.setProvider("test"); + toolkit.setProvider('test'); expect(toolkit.tz).toBeInstanceOf(RpcTzProvider); expect(toolkit.contract).toBeInstanceOf(RpcContractProvider); }); diff --git a/packages/tezos-ts/test/tz/rpc-tz-provider.spec.ts b/packages/tezos-ts/test/tz/rpc-tz-provider.spec.ts index 68a5daccd8..99341faca6 100644 --- a/packages/tezos-ts/test/tz/rpc-tz-provider.spec.ts +++ b/packages/tezos-ts/test/tz/rpc-tz-provider.spec.ts @@ -1,40 +1,40 @@ -import { RpcTzProvider } from "../../src/tz/rpc-tz-provider"; -import BigNumber from "bignumber.js"; +import { RpcTzProvider } from '../../src/tz/rpc-tz-provider'; +import BigNumber from 'bignumber.js'; -describe("RpcTzProvider test", () => { - it("is instantiable", () => { +describe('RpcTzProvider test', () => { + it('is instantiable', () => { expect(new RpcTzProvider(null as any)).toBeInstanceOf(RpcTzProvider); }); - describe("getBalance", () => { - it("calls get balance from the rpc client", async done => { + describe('getBalance', () => { + it('calls get balance from the rpc client', async done => { const mockRpcClient = { - getBalance: jest.fn() + getBalance: jest.fn(), }; - mockRpcClient.getBalance.mockResolvedValue(new BigNumber("10000")); + mockRpcClient.getBalance.mockResolvedValue(new BigNumber('10000')); const provider = new RpcTzProvider(mockRpcClient as any); - const result = await provider.getBalance("test-address"); + const result = await provider.getBalance('test-address'); expect(result).toBeInstanceOf(BigNumber); - expect(result.toString()).toStrictEqual("10000"); - expect(mockRpcClient.getBalance.mock.calls[0][0]).toEqual("test-address"); + expect(result.toString()).toStrictEqual('10000'); + expect(mockRpcClient.getBalance.mock.calls[0][0]).toEqual('test-address'); done(); }); }); - describe("getDelegate", () => { - it("calls get delegate from the rpc client", async done => { + describe('getDelegate', () => { + it('calls get delegate from the rpc client', async done => { const mockRpcClient = { - getDelegate: jest.fn() + getDelegate: jest.fn(), }; - mockRpcClient.getDelegate.mockResolvedValue("KT1G393LjojNshvMdf68XQD24Hwjn7xarzNe"); + mockRpcClient.getDelegate.mockResolvedValue('KT1G393LjojNshvMdf68XQD24Hwjn7xarzNe'); const provider = new RpcTzProvider(mockRpcClient as any); - const result = await provider.getDelegate("test-address"); - expect(result).toStrictEqual("KT1G393LjojNshvMdf68XQD24Hwjn7xarzNe"); - expect(mockRpcClient.getDelegate.mock.calls[0][0]).toEqual("test-address"); + const result = await provider.getDelegate('test-address'); + expect(result).toStrictEqual('KT1G393LjojNshvMdf68XQD24Hwjn7xarzNe'); + expect(mockRpcClient.getDelegate.mock.calls[0][0]).toEqual('test-address'); done(); }); });