From a09ed753762c30486608780389a898df405b0661 Mon Sep 17 00:00:00 2001 From: grum-tez Date: Thu, 1 Dec 2022 16:28:28 +1300 Subject: [PATCH 1/3] Propose tezDate type. Minimal tests --- src/main.ts | 22 ++++++++++++++++++++++ test/main.spec.ts | 25 ++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 612efa0..3802279 100644 --- a/src/main.ts +++ b/src/main.ts @@ -443,6 +443,28 @@ export class Duration implements ArchetypeType { } } +export class TezDate implements ArchetypeType { + private _content: Date + constructor(v: Date = new Date()) { + this._content = new Date(v.setSeconds(0,0)) + } + equals(x: TezDate): boolean { + return this.toSeconds() === x.toSeconds() + } + toSeconds(): number { + return this._content.setSeconds(0,0) + } + addDuration(x: Duration): TezDate { + return new TezDate(new Date(this._content.setSeconds(0,0) + x.toSecond()*1000)) + } + addDurationString(x : string) : TezDate { + return this.addDuration(new Duration(x)) + } + toDate(): Date { + return new Date(this.toSeconds()) + } +} + export class Entrypoint implements ArchetypeType { addr: string name: string diff --git a/test/main.spec.ts b/test/main.spec.ts index ff689fb..09d5085 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -1,5 +1,5 @@ import BigNumber from 'bignumber.js'; -import { Address, Chain_id, Duration, Key, Micheline, mich_to_ticket, Mstring, Nat, Rational, Signature, Ticket, Key_hash } from '../src/main' +import { Address, Chain_id, TezDate, Duration, Key, Micheline, mich_to_ticket, Mstring, Nat, Rational, Signature, Ticket, Key_hash } from '../src/main' describe('ArchetypeType', () => { @@ -150,6 +150,29 @@ describe('Chain_id', () => { }) + + describe('tezDate', () => { + + test('Sucessfully add durations to tezDates', () => { + const now = new Date() + const tezDate = new TezDate(now).addDuration(new Duration('2m')) + const roundedToMinute = new Date(now.setMinutes(0,0,0)) + const nativeDate = new Date(roundedToMinute.getMinutes() + 2) + console.log(nativeDate == tezDate.toDate()) + + }); + + test('Sucessfully add duration string to tezDates', () => { + const now = new Date() + const tezDate = new TezDate(now).addDurationString('2m') + const roundedToMinute = new Date(now.setMinutes(0,0,0)) + const nativeDate = new Date(roundedToMinute.getMinutes() + 2) + console.log(nativeDate == tezDate.toDate()) + + }); + }) + + describe('Key', () => { test('Fails with empty string', () => { const input = "" From 73876e6cf1a785c8ad6943f904880bcb1e8b138d Mon Sep 17 00:00:00 2001 From: grum-tez Date: Mon, 5 Dec 2022 23:03:09 +1300 Subject: [PATCH 2/3] Fix bugs, remove side effects from constructor --- package.json | 3 +- src/main.ts | 20 +- test/main.spec.ts | 856 +++++++++++++++++++++++----------------------- 3 files changed, 445 insertions(+), 434 deletions(-) diff --git a/package.json b/package.json index 19e1ea4..a94b8f4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "test": "jest", "build": "rm -rf ./build && npx tsc --outDir build", - "postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PACKAGE_VERSION && git push --tags" + "postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PACKAGE_VERSION && git push --tags", + "watch-test": "jest --watch" }, "repository": { "type": "git", diff --git a/src/main.ts b/src/main.ts index 3802279..43ea09e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -443,25 +443,27 @@ export class Duration implements ArchetypeType { } } + export class TezDate implements ArchetypeType { private _content: Date constructor(v: Date = new Date()) { - this._content = new Date(v.setSeconds(0,0)) + this._content = new Date(v.getTime() - v.getMilliseconds()) } equals(x: TezDate): boolean { - return this.toSeconds() === x.toSeconds() - } - toSeconds(): number { - return this._content.setSeconds(0,0) + return this.toSecond() === x.toSecond() } - addDuration(x: Duration): TezDate { - return new TezDate(new Date(this._content.setSeconds(0,0) + x.toSecond()*1000)) + toSecond(): number { + return this._content.getTime() / 1000 } - addDurationString(x : string) : TezDate { + addDuration(dur: Duration): TezDate { + return new TezDate( + new Date(this.toSecond()*1000 + dur.toSecond()*1000) + )} + addDurationLiteral(x : string) : TezDate { return this.addDuration(new Duration(x)) } toDate(): Date { - return new Date(this.toSeconds()) + return new Date(this._content) } } diff --git a/test/main.spec.ts b/test/main.spec.ts index 09d5085..371fe5b 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -1,447 +1,455 @@ +import { Tez, cmp_date } from './../src/main'; import BigNumber from 'bignumber.js'; import { Address, Chain_id, TezDate, Duration, Key, Micheline, mich_to_ticket, Mstring, Nat, Rational, Signature, Ticket, Key_hash } from '../src/main' - describe('ArchetypeType', () => { - describe('Address', () => { - test('Fails with empty string', () => { - const input = "" - expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with dummy string', () => { - const input = "dummy" - expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails without prefix', () => { - const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" - expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with bad encoding', () => { - const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" - expect(() => { new Address(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - }) - - test('Succeeds with Valid tz1 User Address', () => { - const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" - expect(new Address(input).toString()).toBe(input) - }) - - test('Succeeds with Valid tz2 User Address', () => { - const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" - expect(new Address(input).toString()).toBe(input) - }) - - test('Succeeds with Valid tz3 User Address', () => { - const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" - expect(new Address(input).toString()).toBe(input) - }) - - test('Succeeds with Valid tz4 User Address', () => { - const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" - expect(new Address(input).toString()).toBe(input) - }) - - test('Succeeds with Valid txr1 User Address', () => { - const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" - expect(new Address(input).toString()).toBe(input) - }) - - test('Succeeds with Valid KT1 Contract Address', () => { - const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" - expect(new Address(input).toString()).toBe(input) - }) - }); - -describe('Chain_id', () => { - test('Fails with empty string', () => { - const input = "" - expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with dummy string', () => { - const input = "dummy" - expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails without prefix', () => { - const input = "XynUjJNZm7wj" - expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with bad encoding', () => { - const input = "NetXynUjJNZm7wj" - expect(() => { new Chain_id(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - }) - - test('Succeeds with Valid Chain_id', () => { - const input = "NetXdQprcVkpaWU" - expect(new Chain_id(input).toString()).toBe(input) - }) - - test('Succeeds with Valid Chain_id (mainnet)', () => { - const input = "NetXynUjJNZm7wi" - expect(new Chain_id(input).toString()).toBe(input) - }) - - }); - - describe('Duration', () => { - - test('Fails with empty string', () => { - expect(() => { new Duration("") }).toThrow("Invalid duration input. Received input: `' Try this format: '_w_d_h_m_s'.") - }); - - test('Fails with dummy string', () => { - expect(() => { new Duration("dummy") }).toThrow("Invalid duration input. Received input: `dummy' Try this format: '_w_d_h_m_s'.") - }); - - test('Fails with number string', () => { - expect(() => { new Duration("0") }).toThrow("Invalid duration input. Received input: `0' Try this format: '_w_d_h_m_s'.") - }); - - test('Fails with typo in unit letter', () => { - const input = "3g8d4h34m18s" - expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") - }); - - test('Fails with typo in unit letter', () => { - const input = "3w8d4h34m18a" - expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") - }); +// describe('Address', () => { +// test('Fails with empty string', () => { +// const input = "" +// expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) +// }) + +// test('Fails with dummy string', () => { +// const input = "dummy" +// expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) +// }) + +// test('Fails without prefix', () => { +// const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" +// expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) +// }) + +// test('Fails with bad encoding', () => { +// const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" +// expect(() => { new Address(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) +// }) + +// test('Succeeds with Valid tz1 User Address', () => { +// const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" +// expect(new Address(input).toString()).toBe(input) +// }) + +// test('Succeeds with Valid tz2 User Address', () => { +// const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" +// expect(new Address(input).toString()).toBe(input) +// }) + +// test('Succeeds with Valid tz3 User Address', () => { +// const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" +// expect(new Address(input).toString()).toBe(input) +// }) + +// test('Succeeds with Valid tz4 User Address', () => { +// const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" +// expect(new Address(input).toString()).toBe(input) +// }) + +// test('Succeeds with Valid txr1 User Address', () => { +// const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" +// expect(new Address(input).toString()).toBe(input) +// }) + +// test('Succeeds with Valid KT1 Contract Address', () => { +// const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" +// expect(new Address(input).toString()).toBe(input) +// }) +// }); + +// describe('Chain_id', () => { +// test('Fails with empty string', () => { +// const input = "" +// expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) +// }) + +// test('Fails with dummy string', () => { +// const input = "dummy" +// expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) +// }) + +// test('Fails without prefix', () => { +// const input = "XynUjJNZm7wj" +// expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) +// }) + +// test('Fails with bad encoding', () => { +// const input = "NetXynUjJNZm7wj" +// expect(() => { new Chain_id(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) +// }) + +// test('Succeeds with Valid Chain_id', () => { +// const input = "NetXdQprcVkpaWU" +// expect(new Chain_id(input).toString()).toBe(input) +// }) + +// test('Succeeds with Valid Chain_id (mainnet)', () => { +// const input = "NetXynUjJNZm7wi" +// expect(new Chain_id(input).toString()).toBe(input) +// }) + +// }); + +// describe('Duration', () => { + +// test('Fails with empty string', () => { +// expect(() => { new Duration("") }).toThrow("Invalid duration input. Received input: `' Try this format: '_w_d_h_m_s'.") +// }); + +// test('Fails with dummy string', () => { +// expect(() => { new Duration("dummy") }).toThrow("Invalid duration input. Received input: `dummy' Try this format: '_w_d_h_m_s'.") +// }); + +// test('Fails with number string', () => { +// expect(() => { new Duration("0") }).toThrow("Invalid duration input. Received input: `0' Try this format: '_w_d_h_m_s'.") +// }); + +// test('Fails with typo in unit letter', () => { +// const input = "3g8d4h34m18s" +// expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") +// }); + +// test('Fails with typo in unit letter', () => { +// const input = "3w8d4h34m18a" +// expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") +// }); + +// it('Simple test', () => { +// expect(new Duration("0s").toSecond()).toBe(0) +// }) + +// it('1 second test', () => { +// expect(new Duration("1s").toSecond()).toBe(1) +// }) + +// it('1 minute test', () => { +// expect(new Duration("1m").toSecond()).toBe(60) +// }) + +// it('1 hour test', () => { +// expect(new Duration("1h").toSecond()).toBe(3600) +// }) + +// it('1 day test', () => { +// expect(new Duration("1d").toSecond()).toBe(86400) +// }) + +// it('1 week test', () => { +// expect(new Duration("1w").toSecond()).toBe(604800) +// }) + +// it('1 week, 1 second test', () => { +// expect(new Duration("1w1s").toSecond()).toBe(604801) +// }) + +// it('1 week, 1 day, 1 hour, 1 minute, 1 second test', () => { +// expect(new Duration("1w1d1h1m1s").toSecond()).toBe(694861) +// }) - it('Simple test', () => { - expect(new Duration("0s").toSecond()).toBe(0) - }) - - it('1 second test', () => { - expect(new Duration("1s").toSecond()).toBe(1) - }) - - it('1 minute test', () => { - expect(new Duration("1m").toSecond()).toBe(60) - }) - - it('1 hour test', () => { - expect(new Duration("1h").toSecond()).toBe(3600) - }) - - it('1 day test', () => { - expect(new Duration("1d").toSecond()).toBe(86400) - }) - - it('1 week test', () => { - expect(new Duration("1w").toSecond()).toBe(604800) - }) - - it('1 week, 1 second test', () => { - expect(new Duration("1w1s").toSecond()).toBe(604801) - }) - - it('1 week, 1 day, 1 hour, 1 minute, 1 second test', () => { - expect(new Duration("1w1d1h1m1s").toSecond()).toBe(694861) - }) - - it('3 weeks, 8 days, 4 hours, 34 minutes, 18 seconds test', () => { - expect(new Duration("3w8d4h34m18s").toSecond()).toBe(2522058) - }) - - }) +// it('3 weeks, 8 days, 4 hours, 34 minutes, 18 seconds test', () => { +// expect(new Duration("3w8d4h34m18s").toSecond()).toBe(2522058) +// }) +// }) describe('tezDate', () => { - test('Sucessfully add durations to tezDates', () => { - const now = new Date() - const tezDate = new TezDate(now).addDuration(new Duration('2m')) - const roundedToMinute = new Date(now.setMinutes(0,0,0)) - const nativeDate = new Date(roundedToMinute.getMinutes() + 2) - console.log(nativeDate == tezDate.toDate()) - + test('Convert Date to TezDate and back again succesfully ', () => { + const native_date_now = new Date() + const tez_date_now = new TezDate(native_date_now) + const native_date_now_two = tez_date_now.toDate() + expect(cmp_date(native_date_now, native_date_now_two)).toEqual(true) }); - test('Sucessfully add duration string to tezDates', () => { - const now = new Date() - const tezDate = new TezDate(now).addDurationString('2m') - const roundedToMinute = new Date(now.setMinutes(0,0,0)) - const nativeDate = new Date(roundedToMinute.getMinutes() + 2) - console.log(nativeDate == tezDate.toDate()) + test('Sucessfully add durations to a TezDate', () => { + const MINUTES = 2 + const native_date_now = new Date() + const native_date_soon = new Date(native_date_now.getTime() + MINUTES*60000) + const tez_date_now = new TezDate(native_date_now) + const tez_date_soon = tez_date_now.addDuration(new Duration(`${MINUTES}m`)) + expect(cmp_date(tez_date_soon.toDate(), native_date_soon)).toEqual(true) }); - }) - - - describe('Key', () => { - test('Fails with empty string', () => { - const input = "" - expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with dummy string', () => { - const input = "dummy" - expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails without prefix', () => { - const input = "vGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" - expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with bad encoding', () => { - const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhja" - expect(() => { new Key(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - }) - - test('Succeeds with Valid edpk Key', () => { - const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" - expect(new Key(input).toString()).toBe(input) - }) - - test('Succeeds with Valid spsk Key', () => { - const input = "sppk7b4TURq2T9rhPLFaSz6mkBCzKzfiBjctQSMorvLD5GSgCduvKuf" - expect(new Key(input).toString()).toBe(input) - }) - - test('Succeeds with Valid p2pk Key', () => { - const input = "p2pk65zwHGP9MdvANKkp267F4VzoKqL8DMNpPfTHUNKbm8S9DUqqdpw" - expect(new Key(input).toString()).toBe(input) - }) - - }); - - describe('Nat', () => { - describe('Constructor', () => { - test('Fails if neg number', () => { - expect(() => { new Nat(-5) }).toThrow("Not an Nat value: -5") - }); - }); - - describe('toString', () => { - - test('Number simple', () => { - expect(new Nat(5).toString()).toBe("5"); - }); - - test('String simple', () => { - expect(new Nat("5").toString()).toBe("5"); - }); - test('Bignumber simple', () => { - expect(new Nat(new BigNumber("5")).toString()).toBe("5"); - }); - - test('String big', () => { - expect(new Nat("9999999999999999999999999999999999999").toString()).toBe("9999999999999999999999999999999999999"); - }); - - test('Bignumber big', () => { - expect(new Nat(new BigNumber("9999999999999999999999999999999999999")).toString()).toBe("9999999999999999999999999999999999999"); - }); - }) + test('Sucessfully add duration string to a TezDate', () => { + const MINUTES = 2 + const native_date_now = new Date() + const native_date_soon = new Date(native_date_now.getTime() + MINUTES*60000) + const tez_date_now = new TezDate(native_date_now) + const tez_date_soon = tez_date_now.addDurationLiteral(`${MINUTES}m`) + expect(cmp_date(tez_date_soon.toDate(), native_date_soon)).toEqual(true) + }); }) - describe('Rational', () => { - describe('toString', () => { - it('String simple', () => { - expect(new Rational("5").toString()).toBe("5"); - }); - - it('Number simple', () => { - expect(new Rational(5).toString()).toBe("5"); - }); - it('Number decimal', () => { - expect(new Rational(5.4464).toString()).toBe("5.4464"); - }); - it('String decimal', () => { - expect(new Rational("5.4464").toString()).toBe("5.4464"); - }); + // describe('Key', () => { + // test('Fails with empty string', () => { + // const input = "" + // expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) - it('String decimal percent', () => { - expect(new Rational("5.4464%").toString()).toBe("0.054464"); - }); + // test('Fails with dummy string', () => { + // const input = "dummy" + // expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) - it('String with big number', () => { - expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).toString()).toBe("100000000000.00435435435425664606"); - }); - - }); - - describe('to_number', () => { - it('String simple', () => { - expect(new Rational("5").to_number()).toBe(5); - }); - - it('Number simple', () => { - expect(new Rational(5).to_number()).toBe(5); - }); - - it('Number decimal', () => { - expect(new Rational(5.4464).to_number()).toBe(5.4464); - }); - - it('String decimal', () => { - expect(new Rational("5.4464").to_number()).toBe(5.4464); - }); - - it('String decimal percent', () => { - expect(new Rational("5.4464%").to_number()).toBe(0.054464); - }); - - it('String with big number', () => { - expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_number()).toBe(100000000000.00435); - }); - }) - - describe('Ticket', () => { - it('Ticket', () => { - const tjson: Micheline = { - "prim": "Pair", - "args": [ - { - "string": "KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe" - }, - { - "string": "info" - }, - { - "int": "1" - } - ] - }; - - const ticket_actual = mich_to_ticket(tjson, (x: Micheline): string => { return (x as Mstring).string }); - expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(true) - expect(new Ticket(new Address("KT1XcpRnLQANuGCJ9SZW3GXVG8BArUKymqtk"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(false) - expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("infu" as string), new Nat(1)).equals(ticket_actual)).toBe(false) - expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(2)).equals(ticket_actual)).toBe(false) - }) - }) - - describe('to_mich', () => { - it('String simple', () => { - expect(JSON.stringify(new Rational("5").to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); - }); - - it('Number simple', () => { - expect(JSON.stringify(new Rational(5).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); - }); - - it('Number decimal', () => { - expect(JSON.stringify(new Rational(5.4464).to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}'); - }); - - it('String decimal', () => { - expect(JSON.stringify(new Rational("5.4464").to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}') - }); - - it('String decimal percent', () => { - expect(JSON.stringify(new Rational("5.4464%").to_mich())).toBe('{"prim":"Pair","args":[{"int":"851"},{"int":"15625"}]}') - }); - - it('String with big number', () => { - expect(JSON.stringify(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5000000000000217717717712832303"},{"int":"50000000000000000000"}]}') - }); - - it('Ticket', () => { - const f = (x: string): Mstring => { return { "string": x } }; - expect(JSON.stringify(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), "info", new Nat(1)).to_mich(f))).toBe('{"prim":"Pair","args":[{"string":"KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"},{"string":"info"},{"int":"1"}]}') - }); - }); - - }) + // test('Fails without prefix', () => { + // const input = "vGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" + // expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) - describe('Signature', () => { - test('Fails with empty string', () => { - const input = "" - expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with dummy string', () => { - const input = "dummy" - expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails without prefix', () => { - const input = "thXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" - expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with bad encoding', () => { - const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vH" - expect(() => { new Signature(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - }) - - test('Succeeds with Valid edsig Signature', () => { - const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" - expect(new Signature(input).toString()).toBe(input) - }) - - test('Succeeds with Valid spsig Signature', () => { - const input = "spsig1VrEwwc2UC4v9v3oYJ96VwiKwdVKK7ZYdMs4JVWNtfj11sRz9RkvPBtCHMiG1LEp44PJBXDh7bAzpDjGoX4bH7heoPuGqa" - expect(new Signature(input).toString()).toBe(input) - }) - - test('Succeeds with Valid p2sig Signature', () => { - const input = "p2siguNBbkRwuMKCyG9NeQb4ETNCDyqUnUCX4T4Um4dFgzCKyA7AzS4a6XBk1Encj4ndXsbK98UYNunZ7vHHFHMhh7jdajUHTY" - expect(new Signature(input).toString()).toBe(input) - }) - - }); - - describe('Key_hash', () => { - test('Fails with empty string', () => { - const input = "" - expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with dummy string', () => { - const input = "dummy" - expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails without prefix', () => { - const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" - expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - }) - - test('Fails with bad encoding', () => { - const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" - expect(() => { new Key_hash(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - }) - - test('Succeeds with Valid tz1 User Address', () => { - const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" - expect(new Key_hash(input).toString()).toBe(input) - }) - - test('Succeeds with Valid tz2 User Address', () => { - const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" - expect(new Key_hash(input).toString()).toBe(input) - }) - - test('Succeeds with Valid tz3 User Address', () => { - const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" - expect(new Key_hash(input).toString()).toBe(input) - }) - - test('Succeeds with Valid tz4 User Address', () => { - const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" - expect(new Key_hash(input).toString()).toBe(input) - }) - - test('Succeeds with Valid txr1 User Address', () => { - const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" - expect(new Key_hash(input).toString()).toBe(input) - }) - - test('Succeeds with Valid KT1 Contract Address', () => { - const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" - expect(new Key_hash(input).toString()).toBe(input) - }) - }); + // test('Fails with bad encoding', () => { + // const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhja" + // expect(() => { new Key(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + // }) + + // test('Succeeds with Valid edpk Key', () => { + // const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" + // expect(new Key(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid spsk Key', () => { + // const input = "sppk7b4TURq2T9rhPLFaSz6mkBCzKzfiBjctQSMorvLD5GSgCduvKuf" + // expect(new Key(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid p2pk Key', () => { + // const input = "p2pk65zwHGP9MdvANKkp267F4VzoKqL8DMNpPfTHUNKbm8S9DUqqdpw" + // expect(new Key(input).toString()).toBe(input) + // }) + + // }); + + // describe('Nat', () => { + // describe('Constructor', () => { + // test('Fails if neg number', () => { + // expect(() => { new Nat(-5) }).toThrow("Not an Nat value: -5") + // }); + // }); + + // describe('toString', () => { + + // test('Number simple', () => { + // expect(new Nat(5).toString()).toBe("5"); + // }); + + // test('String simple', () => { + // expect(new Nat("5").toString()).toBe("5"); + // }); + + // test('Bignumber simple', () => { + // expect(new Nat(new BigNumber("5")).toString()).toBe("5"); + // }); + + // test('String big', () => { + // expect(new Nat("9999999999999999999999999999999999999").toString()).toBe("9999999999999999999999999999999999999"); + // }); + + // test('Bignumber big', () => { + // expect(new Nat(new BigNumber("9999999999999999999999999999999999999")).toString()).toBe("9999999999999999999999999999999999999"); + // }); + // }) + // }) + + // describe('Rational', () => { + // describe('toString', () => { + // it('String simple', () => { + // expect(new Rational("5").toString()).toBe("5"); + // }); + + // it('Number simple', () => { + // expect(new Rational(5).toString()).toBe("5"); + // }); + + // it('Number decimal', () => { + // expect(new Rational(5.4464).toString()).toBe("5.4464"); + // }); + + // it('String decimal', () => { + // expect(new Rational("5.4464").toString()).toBe("5.4464"); + // }); + + // it('String decimal percent', () => { + // expect(new Rational("5.4464%").toString()).toBe("0.054464"); + // }); + + // it('String with big number', () => { + // expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).toString()).toBe("100000000000.00435435435425664606"); + // }); + + // }); + + // describe('to_number', () => { + // it('String simple', () => { + // expect(new Rational("5").to_number()).toBe(5); + // }); + + // it('Number simple', () => { + // expect(new Rational(5).to_number()).toBe(5); + // }); + + // it('Number decimal', () => { + // expect(new Rational(5.4464).to_number()).toBe(5.4464); + // }); + + // it('String decimal', () => { + // expect(new Rational("5.4464").to_number()).toBe(5.4464); + // }); + + // it('String decimal percent', () => { + // expect(new Rational("5.4464%").to_number()).toBe(0.054464); + // }); + + // it('String with big number', () => { + // expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_number()).toBe(100000000000.00435); + // }); + // }) + + // describe('Ticket', () => { + // it('Ticket', () => { + // const tjson: Micheline = { + // "prim": "Pair", + // "args": [ + // { + // "string": "KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe" + // }, + // { + // "string": "info" + // }, + // { + // "int": "1" + // } + // ] + // }; + + // const ticket_actual = mich_to_ticket(tjson, (x: Micheline): string => { return (x as Mstring).string }); + // expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(true) + // expect(new Ticket(new Address("KT1XcpRnLQANuGCJ9SZW3GXVG8BArUKymqtk"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(false) + // expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("infu" as string), new Nat(1)).equals(ticket_actual)).toBe(false) + // expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(2)).equals(ticket_actual)).toBe(false) + // }) + // }) + + // describe('to_mich', () => { + // it('String simple', () => { + // expect(JSON.stringify(new Rational("5").to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); + // }); + + // it('Number simple', () => { + // expect(JSON.stringify(new Rational(5).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); + // }); + + // it('Number decimal', () => { + // expect(JSON.stringify(new Rational(5.4464).to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}'); + // }); + + // it('String decimal', () => { + // expect(JSON.stringify(new Rational("5.4464").to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}') + // }); + + // it('String decimal percent', () => { + // expect(JSON.stringify(new Rational("5.4464%").to_mich())).toBe('{"prim":"Pair","args":[{"int":"851"},{"int":"15625"}]}') + // }); + + // it('String with big number', () => { + // expect(JSON.stringify(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5000000000000217717717712832303"},{"int":"50000000000000000000"}]}') + // }); + + // it('Ticket', () => { + // const f = (x: string): Mstring => { return { "string": x } }; + // expect(JSON.stringify(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), "info", new Nat(1)).to_mich(f))).toBe('{"prim":"Pair","args":[{"string":"KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"},{"string":"info"},{"int":"1"}]}') + // }); + // }); + + // }) + + // describe('Signature', () => { + // test('Fails with empty string', () => { + // const input = "" + // expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) + + // test('Fails with dummy string', () => { + // const input = "dummy" + // expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) + + // test('Fails without prefix', () => { + // const input = "thXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" + // expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) + + // test('Fails with bad encoding', () => { + // const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vH" + // expect(() => { new Signature(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + // }) + + // test('Succeeds with Valid edsig Signature', () => { + // const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" + // expect(new Signature(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid spsig Signature', () => { + // const input = "spsig1VrEwwc2UC4v9v3oYJ96VwiKwdVKK7ZYdMs4JVWNtfj11sRz9RkvPBtCHMiG1LEp44PJBXDh7bAzpDjGoX4bH7heoPuGqa" + // expect(new Signature(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid p2sig Signature', () => { + // const input = "p2siguNBbkRwuMKCyG9NeQb4ETNCDyqUnUCX4T4Um4dFgzCKyA7AzS4a6XBk1Encj4ndXsbK98UYNunZ7vHHFHMhh7jdajUHTY" + // expect(new Signature(input).toString()).toBe(input) + // }) + + // }); + + // describe('Key_hash', () => { + // test('Fails with empty string', () => { + // const input = "" + // expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) + + // test('Fails with dummy string', () => { + // const input = "dummy" + // expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) + + // test('Fails without prefix', () => { + // const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" + // expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + // }) + + // test('Fails with bad encoding', () => { + // const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" + // expect(() => { new Key_hash(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + // }) + + // test('Succeeds with Valid tz1 User Address', () => { + // const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" + // expect(new Key_hash(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid tz2 User Address', () => { + // const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" + // expect(new Key_hash(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid tz3 User Address', () => { + // const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" + // expect(new Key_hash(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid tz4 User Address', () => { + // const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" + // expect(new Key_hash(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid txr1 User Address', () => { + // const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" + // expect(new Key_hash(input).toString()).toBe(input) + // }) + + // test('Succeeds with Valid KT1 Contract Address', () => { + // const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" + // expect(new Key_hash(input).toString()).toBe(input) + // }) + // }); }) From 8710b68977870a1f9427291d19a834093826fb91 Mon Sep 17 00:00:00 2001 From: grum-tez Date: Tue, 6 Dec 2022 12:49:30 +1300 Subject: [PATCH 3/3] uncomment tests --- test/main.spec.ts | 824 +++++++++++++++++++++++----------------------- 1 file changed, 412 insertions(+), 412 deletions(-) diff --git a/test/main.spec.ts b/test/main.spec.ts index 371fe5b..b162ecc 100644 --- a/test/main.spec.ts +++ b/test/main.spec.ts @@ -1,154 +1,154 @@ -import { Tez, cmp_date } from './../src/main'; +import {cmp_date } from './../src/main'; import BigNumber from 'bignumber.js'; import { Address, Chain_id, TezDate, Duration, Key, Micheline, mich_to_ticket, Mstring, Nat, Rational, Signature, Ticket, Key_hash } from '../src/main' describe('ArchetypeType', () => { -// describe('Address', () => { -// test('Fails with empty string', () => { -// const input = "" -// expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) -// }) - -// test('Fails with dummy string', () => { -// const input = "dummy" -// expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) -// }) - -// test('Fails without prefix', () => { -// const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" -// expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) -// }) - -// test('Fails with bad encoding', () => { -// const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" -// expect(() => { new Address(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) -// }) - -// test('Succeeds with Valid tz1 User Address', () => { -// const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" -// expect(new Address(input).toString()).toBe(input) -// }) - -// test('Succeeds with Valid tz2 User Address', () => { -// const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" -// expect(new Address(input).toString()).toBe(input) -// }) - -// test('Succeeds with Valid tz3 User Address', () => { -// const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" -// expect(new Address(input).toString()).toBe(input) -// }) - -// test('Succeeds with Valid tz4 User Address', () => { -// const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" -// expect(new Address(input).toString()).toBe(input) -// }) - -// test('Succeeds with Valid txr1 User Address', () => { -// const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" -// expect(new Address(input).toString()).toBe(input) -// }) - -// test('Succeeds with Valid KT1 Contract Address', () => { -// const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" -// expect(new Address(input).toString()).toBe(input) -// }) -// }); - -// describe('Chain_id', () => { -// test('Fails with empty string', () => { -// const input = "" -// expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) -// }) - -// test('Fails with dummy string', () => { -// const input = "dummy" -// expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) -// }) - -// test('Fails without prefix', () => { -// const input = "XynUjJNZm7wj" -// expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) -// }) - -// test('Fails with bad encoding', () => { -// const input = "NetXynUjJNZm7wj" -// expect(() => { new Chain_id(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) -// }) - -// test('Succeeds with Valid Chain_id', () => { -// const input = "NetXdQprcVkpaWU" -// expect(new Chain_id(input).toString()).toBe(input) -// }) - -// test('Succeeds with Valid Chain_id (mainnet)', () => { -// const input = "NetXynUjJNZm7wi" -// expect(new Chain_id(input).toString()).toBe(input) -// }) - -// }); - -// describe('Duration', () => { - -// test('Fails with empty string', () => { -// expect(() => { new Duration("") }).toThrow("Invalid duration input. Received input: `' Try this format: '_w_d_h_m_s'.") -// }); - -// test('Fails with dummy string', () => { -// expect(() => { new Duration("dummy") }).toThrow("Invalid duration input. Received input: `dummy' Try this format: '_w_d_h_m_s'.") -// }); - -// test('Fails with number string', () => { -// expect(() => { new Duration("0") }).toThrow("Invalid duration input. Received input: `0' Try this format: '_w_d_h_m_s'.") -// }); - -// test('Fails with typo in unit letter', () => { -// const input = "3g8d4h34m18s" -// expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") -// }); - -// test('Fails with typo in unit letter', () => { -// const input = "3w8d4h34m18a" -// expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") -// }); - -// it('Simple test', () => { -// expect(new Duration("0s").toSecond()).toBe(0) -// }) - -// it('1 second test', () => { -// expect(new Duration("1s").toSecond()).toBe(1) -// }) - -// it('1 minute test', () => { -// expect(new Duration("1m").toSecond()).toBe(60) -// }) - -// it('1 hour test', () => { -// expect(new Duration("1h").toSecond()).toBe(3600) -// }) - -// it('1 day test', () => { -// expect(new Duration("1d").toSecond()).toBe(86400) -// }) - -// it('1 week test', () => { -// expect(new Duration("1w").toSecond()).toBe(604800) -// }) - -// it('1 week, 1 second test', () => { -// expect(new Duration("1w1s").toSecond()).toBe(604801) -// }) - -// it('1 week, 1 day, 1 hour, 1 minute, 1 second test', () => { -// expect(new Duration("1w1d1h1m1s").toSecond()).toBe(694861) -// }) + describe('Address', () => { + test('Fails with empty string', () => { + const input = "" + expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with dummy string', () => { + const input = "dummy" + expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails without prefix', () => { + const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" + expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with bad encoding', () => { + const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" + expect(() => { new Address(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + }) + + test('Succeeds with Valid tz1 User Address', () => { + const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" + expect(new Address(input).toString()).toBe(input) + }) + + test('Succeeds with Valid tz2 User Address', () => { + const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" + expect(new Address(input).toString()).toBe(input) + }) + + test('Succeeds with Valid tz3 User Address', () => { + const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" + expect(new Address(input).toString()).toBe(input) + }) + + test('Succeeds with Valid tz4 User Address', () => { + const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" + expect(new Address(input).toString()).toBe(input) + }) + + test('Succeeds with Valid txr1 User Address', () => { + const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" + expect(new Address(input).toString()).toBe(input) + }) + + test('Succeeds with Valid KT1 Contract Address', () => { + const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" + expect(new Address(input).toString()).toBe(input) + }) + }); + +describe('Chain_id', () => { + test('Fails with empty string', () => { + const input = "" + expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with dummy string', () => { + const input = "dummy" + expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails without prefix', () => { + const input = "XynUjJNZm7wj" + expect(() => { new Chain_id(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with bad encoding', () => { + const input = "NetXynUjJNZm7wj" + expect(() => { new Chain_id(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + }) + + test('Succeeds with Valid Chain_id', () => { + const input = "NetXdQprcVkpaWU" + expect(new Chain_id(input).toString()).toBe(input) + }) + + test('Succeeds with Valid Chain_id (mainnet)', () => { + const input = "NetXynUjJNZm7wi" + expect(new Chain_id(input).toString()).toBe(input) + }) + + }); + + describe('Duration', () => { + + test('Fails with empty string', () => { + expect(() => { new Duration("") }).toThrow("Invalid duration input. Received input: `' Try this format: '_w_d_h_m_s'.") + }); + + test('Fails with dummy string', () => { + expect(() => { new Duration("dummy") }).toThrow("Invalid duration input. Received input: `dummy' Try this format: '_w_d_h_m_s'.") + }); + + test('Fails with number string', () => { + expect(() => { new Duration("0") }).toThrow("Invalid duration input. Received input: `0' Try this format: '_w_d_h_m_s'.") + }); + + test('Fails with typo in unit letter', () => { + const input = "3g8d4h34m18s" + expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") + }); + + test('Fails with typo in unit letter', () => { + const input = "3w8d4h34m18a" + expect(() => { new Duration(input) }).toThrow("Invalid duration input. Received input: `" + input + "' Try this format: '_w_d_h_m_s'.") + }); + + it('Simple test', () => { + expect(new Duration("0s").toSecond()).toBe(0) + }) + + it('1 second test', () => { + expect(new Duration("1s").toSecond()).toBe(1) + }) -// it('3 weeks, 8 days, 4 hours, 34 minutes, 18 seconds test', () => { -// expect(new Duration("3w8d4h34m18s").toSecond()).toBe(2522058) -// }) + it('1 minute test', () => { + expect(new Duration("1m").toSecond()).toBe(60) + }) -// }) + it('1 hour test', () => { + expect(new Duration("1h").toSecond()).toBe(3600) + }) + + it('1 day test', () => { + expect(new Duration("1d").toSecond()).toBe(86400) + }) + + it('1 week test', () => { + expect(new Duration("1w").toSecond()).toBe(604800) + }) + + it('1 week, 1 second test', () => { + expect(new Duration("1w1s").toSecond()).toBe(604801) + }) + + it('1 week, 1 day, 1 hour, 1 minute, 1 second test', () => { + expect(new Duration("1w1d1h1m1s").toSecond()).toBe(694861) + }) + + it('3 weeks, 8 days, 4 hours, 34 minutes, 18 seconds test', () => { + expect(new Duration("3w8d4h34m18s").toSecond()).toBe(2522058) + }) + + }) describe('tezDate', () => { @@ -181,275 +181,275 @@ describe('ArchetypeType', () => { - // describe('Key', () => { - // test('Fails with empty string', () => { - // const input = "" - // expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) + describe('Key', () => { + test('Fails with empty string', () => { + const input = "" + expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with dummy string', () => { + const input = "dummy" + expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails without prefix', () => { + const input = "vGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" + expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with bad encoding', () => { + const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhja" + expect(() => { new Key(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + }) + + test('Succeeds with Valid edpk Key', () => { + const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" + expect(new Key(input).toString()).toBe(input) + }) + + test('Succeeds with Valid spsk Key', () => { + const input = "sppk7b4TURq2T9rhPLFaSz6mkBCzKzfiBjctQSMorvLD5GSgCduvKuf" + expect(new Key(input).toString()).toBe(input) + }) + + test('Succeeds with Valid p2pk Key', () => { + const input = "p2pk65zwHGP9MdvANKkp267F4VzoKqL8DMNpPfTHUNKbm8S9DUqqdpw" + expect(new Key(input).toString()).toBe(input) + }) + + }); + + describe('Nat', () => { + describe('Constructor', () => { + test('Fails if neg number', () => { + expect(() => { new Nat(-5) }).toThrow("Not an Nat value: -5") + }); + }); + + describe('toString', () => { + + test('Number simple', () => { + expect(new Nat(5).toString()).toBe("5"); + }); + + test('String simple', () => { + expect(new Nat("5").toString()).toBe("5"); + }); + + test('Bignumber simple', () => { + expect(new Nat(new BigNumber("5")).toString()).toBe("5"); + }); + + test('String big', () => { + expect(new Nat("9999999999999999999999999999999999999").toString()).toBe("9999999999999999999999999999999999999"); + }); + + test('Bignumber big', () => { + expect(new Nat(new BigNumber("9999999999999999999999999999999999999")).toString()).toBe("9999999999999999999999999999999999999"); + }); + }) + }) + + describe('Rational', () => { + describe('toString', () => { + it('String simple', () => { + expect(new Rational("5").toString()).toBe("5"); + }); + + it('Number simple', () => { + expect(new Rational(5).toString()).toBe("5"); + }); + + it('Number decimal', () => { + expect(new Rational(5.4464).toString()).toBe("5.4464"); + }); + + it('String decimal', () => { + expect(new Rational("5.4464").toString()).toBe("5.4464"); + }); + + it('String decimal percent', () => { + expect(new Rational("5.4464%").toString()).toBe("0.054464"); + }); - // test('Fails with dummy string', () => { - // const input = "dummy" - // expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) + it('String with big number', () => { + expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).toString()).toBe("100000000000.00435435435425664606"); + }); - // test('Fails without prefix', () => { - // const input = "vGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" - // expect(() => { new Key(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) + }); + + describe('to_number', () => { + it('String simple', () => { + expect(new Rational("5").to_number()).toBe(5); + }); + + it('Number simple', () => { + expect(new Rational(5).to_number()).toBe(5); + }); + + it('Number decimal', () => { + expect(new Rational(5.4464).to_number()).toBe(5.4464); + }); + + it('String decimal', () => { + expect(new Rational("5.4464").to_number()).toBe(5.4464); + }); + + it('String decimal percent', () => { + expect(new Rational("5.4464%").to_number()).toBe(0.054464); + }); + + it('String with big number', () => { + expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_number()).toBe(100000000000.00435); + }); + }) + + describe('Ticket', () => { + it('Ticket', () => { + const tjson: Micheline = { + "prim": "Pair", + "args": [ + { + "string": "KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe" + }, + { + "string": "info" + }, + { + "int": "1" + } + ] + }; + + const ticket_actual = mich_to_ticket(tjson, (x: Micheline): string => { return (x as Mstring).string }); + expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(true) + expect(new Ticket(new Address("KT1XcpRnLQANuGCJ9SZW3GXVG8BArUKymqtk"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(false) + expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("infu" as string), new Nat(1)).equals(ticket_actual)).toBe(false) + expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(2)).equals(ticket_actual)).toBe(false) + }) + }) + + describe('to_mich', () => { + it('String simple', () => { + expect(JSON.stringify(new Rational("5").to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); + }); + + it('Number simple', () => { + expect(JSON.stringify(new Rational(5).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); + }); + + it('Number decimal', () => { + expect(JSON.stringify(new Rational(5.4464).to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}'); + }); + + it('String decimal', () => { + expect(JSON.stringify(new Rational("5.4464").to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}') + }); + + it('String decimal percent', () => { + expect(JSON.stringify(new Rational("5.4464%").to_mich())).toBe('{"prim":"Pair","args":[{"int":"851"},{"int":"15625"}]}') + }); + + it('String with big number', () => { + expect(JSON.stringify(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5000000000000217717717712832303"},{"int":"50000000000000000000"}]}') + }); + + it('Ticket', () => { + const f = (x: string): Mstring => { return { "string": x } }; + expect(JSON.stringify(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), "info", new Nat(1)).to_mich(f))).toBe('{"prim":"Pair","args":[{"string":"KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"},{"string":"info"},{"int":"1"}]}') + }); + }); + + }) - // test('Fails with bad encoding', () => { - // const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhja" - // expect(() => { new Key(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - // }) - - // test('Succeeds with Valid edpk Key', () => { - // const input = "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn" - // expect(new Key(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid spsk Key', () => { - // const input = "sppk7b4TURq2T9rhPLFaSz6mkBCzKzfiBjctQSMorvLD5GSgCduvKuf" - // expect(new Key(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid p2pk Key', () => { - // const input = "p2pk65zwHGP9MdvANKkp267F4VzoKqL8DMNpPfTHUNKbm8S9DUqqdpw" - // expect(new Key(input).toString()).toBe(input) - // }) - - // }); - - // describe('Nat', () => { - // describe('Constructor', () => { - // test('Fails if neg number', () => { - // expect(() => { new Nat(-5) }).toThrow("Not an Nat value: -5") - // }); - // }); - - // describe('toString', () => { - - // test('Number simple', () => { - // expect(new Nat(5).toString()).toBe("5"); - // }); - - // test('String simple', () => { - // expect(new Nat("5").toString()).toBe("5"); - // }); - - // test('Bignumber simple', () => { - // expect(new Nat(new BigNumber("5")).toString()).toBe("5"); - // }); - - // test('String big', () => { - // expect(new Nat("9999999999999999999999999999999999999").toString()).toBe("9999999999999999999999999999999999999"); - // }); - - // test('Bignumber big', () => { - // expect(new Nat(new BigNumber("9999999999999999999999999999999999999")).toString()).toBe("9999999999999999999999999999999999999"); - // }); - // }) - // }) - - // describe('Rational', () => { - // describe('toString', () => { - // it('String simple', () => { - // expect(new Rational("5").toString()).toBe("5"); - // }); - - // it('Number simple', () => { - // expect(new Rational(5).toString()).toBe("5"); - // }); - - // it('Number decimal', () => { - // expect(new Rational(5.4464).toString()).toBe("5.4464"); - // }); - - // it('String decimal', () => { - // expect(new Rational("5.4464").toString()).toBe("5.4464"); - // }); - - // it('String decimal percent', () => { - // expect(new Rational("5.4464%").toString()).toBe("0.054464"); - // }); - - // it('String with big number', () => { - // expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).toString()).toBe("100000000000.00435435435425664606"); - // }); - - // }); - - // describe('to_number', () => { - // it('String simple', () => { - // expect(new Rational("5").to_number()).toBe(5); - // }); - - // it('Number simple', () => { - // expect(new Rational(5).to_number()).toBe(5); - // }); - - // it('Number decimal', () => { - // expect(new Rational(5.4464).to_number()).toBe(5.4464); - // }); - - // it('String decimal', () => { - // expect(new Rational("5.4464").to_number()).toBe(5.4464); - // }); - - // it('String decimal percent', () => { - // expect(new Rational("5.4464%").to_number()).toBe(0.054464); - // }); - - // it('String with big number', () => { - // expect(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_number()).toBe(100000000000.00435); - // }); - // }) - - // describe('Ticket', () => { - // it('Ticket', () => { - // const tjson: Micheline = { - // "prim": "Pair", - // "args": [ - // { - // "string": "KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe" - // }, - // { - // "string": "info" - // }, - // { - // "int": "1" - // } - // ] - // }; - - // const ticket_actual = mich_to_ticket(tjson, (x: Micheline): string => { return (x as Mstring).string }); - // expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(true) - // expect(new Ticket(new Address("KT1XcpRnLQANuGCJ9SZW3GXVG8BArUKymqtk"), ("info" as string), new Nat(1)).equals(ticket_actual)).toBe(false) - // expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("infu" as string), new Nat(1)).equals(ticket_actual)).toBe(false) - // expect(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), ("info" as string), new Nat(2)).equals(ticket_actual)).toBe(false) - // }) - // }) - - // describe('to_mich', () => { - // it('String simple', () => { - // expect(JSON.stringify(new Rational("5").to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); - // }); - - // it('Number simple', () => { - // expect(JSON.stringify(new Rational(5).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5"},{"int":"1"}]}'); - // }); - - // it('Number decimal', () => { - // expect(JSON.stringify(new Rational(5.4464).to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}'); - // }); - - // it('String decimal', () => { - // expect(JSON.stringify(new Rational("5.4464").to_mich())).toBe('{"prim":"Pair","args":[{"int":"3404"},{"int":"625"}]}') - // }); - - // it('String decimal percent', () => { - // expect(JSON.stringify(new Rational("5.4464%").to_mich())).toBe('{"prim":"Pair","args":[{"int":"851"},{"int":"15625"}]}') - // }); - - // it('String with big number', () => { - // expect(JSON.stringify(new Rational("99999999999999999999999956456456456999999999", new BigNumber("999999999999956456456456999999999")).to_mich())).toBe('{"prim":"Pair","args":[{"int":"5000000000000217717717712832303"},{"int":"50000000000000000000"}]}') - // }); - - // it('Ticket', () => { - // const f = (x: string): Mstring => { return { "string": x } }; - // expect(JSON.stringify(new Ticket(new Address("KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"), "info", new Nat(1)).to_mich(f))).toBe('{"prim":"Pair","args":[{"string":"KT1PkBvorKLwdrP3UWUMo3ytZrRUq3wqfFGe"},{"string":"info"},{"int":"1"}]}') - // }); - // }); - - // }) - - // describe('Signature', () => { - // test('Fails with empty string', () => { - // const input = "" - // expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) - - // test('Fails with dummy string', () => { - // const input = "dummy" - // expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) - - // test('Fails without prefix', () => { - // const input = "thXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" - // expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) - - // test('Fails with bad encoding', () => { - // const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vH" - // expect(() => { new Signature(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - // }) - - // test('Succeeds with Valid edsig Signature', () => { - // const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" - // expect(new Signature(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid spsig Signature', () => { - // const input = "spsig1VrEwwc2UC4v9v3oYJ96VwiKwdVKK7ZYdMs4JVWNtfj11sRz9RkvPBtCHMiG1LEp44PJBXDh7bAzpDjGoX4bH7heoPuGqa" - // expect(new Signature(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid p2sig Signature', () => { - // const input = "p2siguNBbkRwuMKCyG9NeQb4ETNCDyqUnUCX4T4Um4dFgzCKyA7AzS4a6XBk1Encj4ndXsbK98UYNunZ7vHHFHMhh7jdajUHTY" - // expect(new Signature(input).toString()).toBe(input) - // }) - - // }); - - // describe('Key_hash', () => { - // test('Fails with empty string', () => { - // const input = "" - // expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) - - // test('Fails with dummy string', () => { - // const input = "dummy" - // expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) - - // test('Fails without prefix', () => { - // const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" - // expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) - // }) - - // test('Fails with bad encoding', () => { - // const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" - // expect(() => { new Key_hash(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) - // }) - - // test('Succeeds with Valid tz1 User Address', () => { - // const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" - // expect(new Key_hash(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid tz2 User Address', () => { - // const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" - // expect(new Key_hash(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid tz3 User Address', () => { - // const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" - // expect(new Key_hash(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid tz4 User Address', () => { - // const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" - // expect(new Key_hash(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid txr1 User Address', () => { - // const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" - // expect(new Key_hash(input).toString()).toBe(input) - // }) - - // test('Succeeds with Valid KT1 Contract Address', () => { - // const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" - // expect(new Key_hash(input).toString()).toBe(input) - // }) - // }); + describe('Signature', () => { + test('Fails with empty string', () => { + const input = "" + expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with dummy string', () => { + const input = "dummy" + expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails without prefix', () => { + const input = "thXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" + expect(() => { new Signature(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with bad encoding', () => { + const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vH" + expect(() => { new Signature(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + }) + + test('Succeeds with Valid edsig Signature', () => { + const input = "edsigthXYBNW7i5E1WNd87fBRJKacJjK5amJVKcyXd6fGxmnQo2ESmmdgN6qJXgbUVJDXha8xi96r9GqjsPorWWpPEwXNG3W8vG" + expect(new Signature(input).toString()).toBe(input) + }) + + test('Succeeds with Valid spsig Signature', () => { + const input = "spsig1VrEwwc2UC4v9v3oYJ96VwiKwdVKK7ZYdMs4JVWNtfj11sRz9RkvPBtCHMiG1LEp44PJBXDh7bAzpDjGoX4bH7heoPuGqa" + expect(new Signature(input).toString()).toBe(input) + }) + + test('Succeeds with Valid p2sig Signature', () => { + const input = "p2siguNBbkRwuMKCyG9NeQb4ETNCDyqUnUCX4T4Um4dFgzCKyA7AzS4a6XBk1Encj4ndXsbK98UYNunZ7vHHFHMhh7jdajUHTY" + expect(new Signature(input).toString()).toBe(input) + }) + + }); + + describe('Key_hash', () => { + test('Fails with empty string', () => { + const input = "" + expect(() => { new Address(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with dummy string', () => { + const input = "dummy" + expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails without prefix', () => { + const input = "VSUr8wwzhLAzempoch5d6hLRiTh8Cjcjbsaf" + expect(() => { new Key_hash(input) }).toThrow(`No matching prefix found. Received input: ${input}`) + }) + + test('Fails with bad encoding', () => { + const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8CjcIl" + expect(() => { new Key_hash(input) }).toThrow(`Input is not b58 encoding compatible. Received input: ${input}`) + }) + + test('Succeeds with Valid tz1 User Address', () => { + const input = "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" + expect(new Key_hash(input).toString()).toBe(input) + }) + + test('Succeeds with Valid tz2 User Address', () => { + const input = "tz28US7zJ7rLdWke75XEM3T5cLWCCxjnP4zf" + expect(new Key_hash(input).toString()).toBe(input) + }) + + test('Succeeds with Valid tz3 User Address', () => { + const input = "tz3hFR7NZtjT2QtzgMQnWb4xMuD6yt2YzXUt" + expect(new Key_hash(input).toString()).toBe(input) + }) + + test('Succeeds with Valid tz4 User Address', () => { + const input = "tz4HVR6aty9KwsQFHh81C1G7gBdhxT8kuytm" + expect(new Key_hash(input).toString()).toBe(input) + }) + + test('Succeeds with Valid txr1 User Address', () => { + const input = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" + expect(new Key_hash(input).toString()).toBe(input) + }) + + test('Succeeds with Valid KT1 Contract Address', () => { + const input = "KT1AaaBSo5AE6Eo8fpEN5xhCD4w3kHStafxk" + expect(new Key_hash(input).toString()).toBe(input) + }) + }); })