diff --git a/README.md b/README.md index 1b001782..32797381 100644 --- a/README.md +++ b/README.md @@ -837,6 +837,10 @@ Running the unit tests require node.js v8.15+. # Change Log +### 0.26.0 +- Utilizing simpleledger/slp-mdm package, update associated unit tests +- Update BigNumber library + ### 0.25.6 - Update unit tests and examples for bchd based network - Patch missing tokenIdHex in getTokenInformation after recent refactoring diff --git a/lib/localvalidator.ts b/lib/localvalidator.ts index 498df2fb..39514c83 100644 --- a/lib/localvalidator.ts +++ b/lib/localvalidator.ts @@ -170,7 +170,6 @@ export class LocalValidator implements SlpValidator { const txn: Bitcore.Transaction = new Bitcore.Transaction(this.cachedRawTransactions[txid]); let slpmsg: SlpTransactionDetails; try { - // @ts-ignore slpmsg = this.cachedValidations[txid].details = this.slp.parseSlpOutputScript(txn.outputs[0]._scriptBuffer); if (slpmsg.transactionType === SlpTransactionType.GENESIS) { slpmsg.tokenIdHex = txid; diff --git a/lib/slptokentype1.ts b/lib/slptokentype1.ts index bf2a4777..329cf4e4 100644 --- a/lib/slptokentype1.ts +++ b/lib/slptokentype1.ts @@ -1,267 +1,42 @@ -import { Utils } from './utils'; -import BigNumber from 'bignumber.js'; +import BigNumber from "bignumber.js"; +import { TokenType1 } from "slp-mdm"; export class SlpTokenType1 { - static get lokadIdHex() { return "534c5000" } - - static buildGenesisOpReturn(ticker: string|null, name: string|null, documentUri:string|null, documentHashHex: string|null, decimals: number, batonVout:number|null, initialQuantity:BigNumber, type=0x01) { - let script: (number|number[])[] = []; - - // OP Return Prefix - script.push(0x6a) - - // Lokad Id - let lokadId = Buffer.from(this.lokadIdHex, 'hex') - script.push(Utils.getPushDataOpcode(lokadId)) - lokadId.forEach((item) => script.push(item)) - - // Token Version/Type - if(![0x01, 0x41, 0x81].includes(type)) - throw Error("Unable to create Genesis for this token type.") - let tokenVersionType = type; - script.push(Utils.getPushDataOpcode([tokenVersionType])) - script.push(tokenVersionType) - - // Transaction Type - let transactionType = Buffer.from('GENESIS') - script.push(Utils.getPushDataOpcode(transactionType)) - transactionType.forEach((item) => script.push(item)) - - // Ticker - if (ticker && typeof ticker !== 'string'){ - throw Error("ticker must be a string") - } else if (!ticker || ticker.length === 0) { - [0x4c, 0x00].forEach((item) => script.push(item)) - } else { - let tickerBuf = Buffer.from(ticker, 'utf8') - script.push(Utils.getPushDataOpcode(tickerBuf)) - tickerBuf.forEach((item) => script.push(item)) - } - - // Name - if (name && typeof name !== 'string') { - throw Error("name must be a string") - } else if (!name || name.length === 0) { - [0x4c, 0x00].forEach((item) => script.push(item)) - } else { - let nameBuf = Buffer.from(name, 'utf8') - script.push(Utils.getPushDataOpcode(nameBuf)) - nameBuf.forEach((item) => script.push(item)) - } - - // Document URL - if (documentUri && typeof documentUri !== 'string') { - throw Error("documentUri must be a string") - } else if (!documentUri || documentUri.length === 0) { - [0x4c, 0x00].forEach((item) => script.push(item)) - } else { - let documentUriBuf = Buffer.from(documentUri, 'ascii') - script.push(Utils.getPushDataOpcode(documentUriBuf)) - documentUriBuf.forEach((item) => script.push(item)) - } - - // check Token Document Hash should be hexademical chracters. - var re = /^[0-9a-fA-F]+$/; - - // Document Hash - if (!documentHashHex || documentHashHex.length === 0) { - [0x4c, 0x00].forEach((item) => script.push(item)) - } else if (documentHashHex.length === 64 && re.test(documentHashHex)) { - let documentHashBuf = Buffer.from(documentHashHex, 'hex') - script.push(Utils.getPushDataOpcode(documentHashBuf)) - documentHashBuf.forEach((item) => script.push(item)) - } else { - throw Error("Document hash must be provided as a 64 character hex string") - } - - // Decimals - if (decimals === null || decimals === undefined || decimals < 0 || decimals > 9) { - throw Error("Decimals property must be in range 0 to 9") - } else { - script.push(Utils.getPushDataOpcode([decimals])) - script.push(decimals) - } - - // Baton Vout - if (batonVout === null || batonVout === undefined) { - [0x4c, 0x00].forEach((item) => script.push(item)) - } else { - if (batonVout < 2 || batonVout > 255 || !(typeof batonVout == 'number')) - throw Error("Baton vout must a number and greater than 1 and less than 256.") - - script.push(Utils.getPushDataOpcode([batonVout])) - script.push(batonVout) - } - - // Initial Quantity - let MAX_QTY = new BigNumber('18446744073709551615'); - - try { - initialQuantity.absoluteValue() - } catch(_) { - throw Error("Amount must be an instance of BigNumber"); - } - - if (initialQuantity.isGreaterThan(MAX_QTY)) - throw new Error("Maximum genesis value exceeded. Reduce input quantity below 18446744073709551615."); - - if (initialQuantity.isLessThan(0)) - throw Error("Genesis quantity must be greater than 0."); - - if (!initialQuantity.modulo(1).isEqualTo(new BigNumber(0))) - throw Error("Genesis quantity must be a whole number."); - - let initialQuantityBuf = Utils.int2FixedBuffer(initialQuantity) - script.push(Utils.getPushDataOpcode(initialQuantityBuf)) - initialQuantityBuf.forEach((item) => script.push(item)) - - let encodedScript = Utils.encodeScript(script) - if (encodedScript.length > 223) { - throw Error("Script too long, must be less than 223 bytes.") - } - return encodedScript - } - - static buildSendOpReturn(tokenIdHex: string, outputQtyArray: BigNumber[], type=0x01) { - let script: (number|number[])[] = []; - - // OP Return Prefix - script.push(0x6a) - - // Lokad Id - let lokadId = Buffer.from(this.lokadIdHex, 'hex') - script.push(Utils.getPushDataOpcode(lokadId)) - lokadId.forEach((item) => script.push(item)) - - // Token Version/Type - if(![0x01, 0x41, 0x81].includes(type)) - throw Error("Unable to create Genesis for this token type.") - let tokenVersionType = type - script.push(Utils.getPushDataOpcode([tokenVersionType])) - script.push(tokenVersionType) - - // Transaction Type - let transactionType = Buffer.from('SEND') - script.push(Utils.getPushDataOpcode(transactionType)) - transactionType.forEach((item) => script.push(item)) - - // Token Id - // check Token Id should be hexademical chracters. - let re = /^([A-Fa-f0-9]{2}){32,32}$/; - if (typeof tokenIdHex !== 'string' || !re.test(tokenIdHex)) { - throw Error("TokenIdHex must be provided as a 64 character hex string.") - } - let tokenId = Buffer.from(tokenIdHex, 'hex') - script.push(Utils.getPushDataOpcode(tokenId)) - tokenId.forEach((item) => script.push(item)) - - // Output Quantities - if (outputQtyArray.length > 19) { - throw Error("Cannot have more than 19 SLP token outputs.") - } - if (outputQtyArray.length < 1) { - throw Error("Cannot have less than 1 SLP token output.") - } - outputQtyArray.forEach((outputQty) => { - try { - outputQty.absoluteValue() - } catch(_) { - throw Error("Amount must be an instance of BigNumber"); + static get lokadIdHex() { return "534c5000"; } + + public static buildGenesisOpReturn( + ticker: string|null, + name: string|null, + documentUrl: string|null, + documentHashHex: string|null, + decimals: number, + batonVout: number|null, + initialQuantity: BigNumber, + type= 0x01, + ) { + if (decimals === null || decimals === undefined) { + throw Error("Decimals property must be in range 0 to 9"); } - - let MAX_QTY = new BigNumber('18446744073709551615'); - - if (outputQty.isGreaterThan(MAX_QTY)) - throw new Error("Maximum value exceeded. Reduce input quantity below 18446744073709551615."); - - if (outputQty.isLessThan(0)) - throw Error("All Send outputs must be greater than 0."); - - if (!outputQty.modulo(1).isEqualTo(new BigNumber(0))) - throw Error("All Send outputs must be a whole number."); - - let qtyBuffer = Utils.int2FixedBuffer(outputQty) - script.push(Utils.getPushDataOpcode(qtyBuffer)) - qtyBuffer.forEach((item) => script.push(item)) - }) - - let encodedScript = Utils.encodeScript(script) - if (encodedScript.length > 223) { - throw Error("Script too long, must be less than 223 bytes.") - } - return encodedScript + if (ticker !== null && typeof ticker !== "string") { + throw Error("ticker must be a string"); + } + if (name !== null && typeof name !== "string") { + throw Error("name must be a string"); + } + let res = TokenType1.genesis( + ticker || "", name || "", documentUrl || "", + documentHashHex || "", decimals || 0, batonVout, initialQuantity); + if (res.length > 223) { + throw Error("Script too long, must be less than or equal to 223 bytes."); + } + return res; } - static buildMintOpReturn(tokenIdHex: string, batonVout: number|null, mintQuantity: BigNumber, type=0x01) { - let script: (number|number[])[] = []; - - // OP Return Prefix - script.push(0x6a) - - // Lokad Id - let lokadId = Buffer.from(this.lokadIdHex, 'hex') - script.push(Utils.getPushDataOpcode(lokadId)) - lokadId.forEach((item) => script.push(item)) - - // Token Version/Type - if(![0x01, 0x81].includes(type)) - throw Error("Unable to create Genesis for this token type.") - let tokenVersionType = type - script.push(Utils.getPushDataOpcode([tokenVersionType])) - script.push(tokenVersionType) - - // Transaction Type - let transactionType = Buffer.from('MINT') - script.push(Utils.getPushDataOpcode(transactionType)) - transactionType.forEach((item) => script.push(item)) - - // Token Id - // check Token Id should be hexademical chracters. - let re = /^([A-Fa-f0-9]{2}){32,32}$/; - if (typeof tokenIdHex !== 'string' || !re.test(tokenIdHex)) { - throw Error("TokenIdHex must be provided as a 64 character hex string.") - } - let tokenId = Buffer.from(tokenIdHex, 'hex') - script.push(Utils.getPushDataOpcode(tokenId)) - tokenId.forEach((item) => script.push(item)) - - // Baton Vout - if (batonVout === null || batonVout === undefined) { - [0x4c, 0x00].forEach((item) => script.push(item)) - } else { - if (batonVout < 2 || batonVout > 255 || !(typeof batonVout == 'number')) - throw Error("Baton vout must a number and greater than 1 and less than 256.") - - script.push(Utils.getPushDataOpcode([batonVout])) - script.push(batonVout) - } - - // Initial Quantity - let MAX_QTY = new BigNumber('18446744073709551615'); - - try { - mintQuantity.absoluteValue() - } catch(_) { - throw Error("Amount must be an instance of BigNumber"); - } - - if (mintQuantity.isGreaterThan(MAX_QTY)) - throw new Error("Maximum mint value exceeded. Reduce input quantity below 18446744073709551615."); - - if (mintQuantity.isLessThan(0)) - throw Error("Mint quantity must be greater than 0."); - - if (!mintQuantity.modulo(1).isEqualTo(new BigNumber(0))) - throw Error("Mint quantity must be a whole number."); - - let initialQuantityBuf = Utils.int2FixedBuffer(mintQuantity) - script.push(Utils.getPushDataOpcode(initialQuantityBuf)) - initialQuantityBuf.forEach((item) => script.push(item)) + public static buildSendOpReturn(tokenIdHex: string, outputQtyArray: BigNumber[], type= 0x01) { + return TokenType1.send(tokenIdHex, outputQtyArray); + } - let encodedScript = Utils.encodeScript(script) - if (encodedScript.length > 223) { - throw Error("Script too long, must be less than 223 bytes.") - } - return encodedScript + public static buildMintOpReturn(tokenIdHex: string, batonVout: number|null, mintQuantity: BigNumber, type= 0x01) { + return TokenType1.mint(tokenIdHex, batonVout, mintQuantity); } -} \ No newline at end of file +} diff --git a/lib/transactionhelpers.ts b/lib/transactionhelpers.ts index d8fefa86..0d625eca 100644 --- a/lib/transactionhelpers.ts +++ b/lib/transactionhelpers.ts @@ -565,7 +565,6 @@ export class TransactionHelpers { throw Error("Was not able to set input script for index="+s.index); // actually set the input's scriptSig property - const script = new Bitcore.Script(bip62Encoded); txn.inputs[s.index].setScript(script); // console.log("scriptSig for index", s.input_index, ":", bip62Encoded.toString('hex')) diff --git a/lib/utils.ts b/lib/utils.ts index 705ee76a..220db124 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -128,30 +128,6 @@ export class Utils { return (new BigNumber(amount.readUInt32BE(0).toString())).multipliedBy(2 ** 32).plus(amount.readUInt32BE(4).toString()); } - // This is for encoding Script in scriptPubKey OP_RETURN scripts, where BIP62.3 does not apply - public static encodeScript(script: (number|number[])[]) { - const bufferSize = script.reduce((acc: number, cur) => { - if (Array.isArray(cur)) { return acc + cur.length; } - else { return acc + 1; } - }, 0); - - const buffer = Buffer.allocUnsafe(bufferSize); - let offset = 0; - script.forEach((scriptItem) => { - if (Array.isArray(scriptItem)) { - scriptItem.forEach((item) => { - buffer.writeUInt8(item, offset); - offset += 1; - }); - } else { - buffer.writeUInt8(scriptItem, offset); - offset += 1; - } - }); - - return buffer; - } - public static buildSlpUri(address: string, amountBch?: number, amountToken?: number, tokenId?: string): string { let uri = ""; if (!this.isSlpAddress(address)) { diff --git a/package-lock.json b/package-lock.json index c5b4bedd..4446e97f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "slpjs", - "version": "0.25.6", + "version": "0.26.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -246,19 +246,6 @@ "wif": "^2.0.1" } }, - "@improbable-eng/grpc-web": { - "version": "0.9.6", - "resolved": "https://registry.npmjs.org/@improbable-eng/grpc-web/-/grpc-web-0.9.6.tgz", - "integrity": "sha512-Qs4++T+UvFmrgELd70VX9WbqiP22rk+a28fiwmerrCfrb2gt+mYAqO5xa5GxvHnL+geXcCbgZOeVWxQXrvXB4Q==", - "requires": { - "browser-headers": "^0.4.0" - } - }, - "@improbable-eng/grpc-web-node-http-transport": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/@improbable-eng/grpc-web-node-http-transport/-/grpc-web-node-http-transport-0.12.0.tgz", - "integrity": "sha512-+Kjz+Dktfz5LKTZA9ZW/Vlww6HF9KaKz4x2mVe1O8CJdOP2WfzC+KY8L6EWMqVLrV4MvdBuQdSgDmvSJz+OGuA==" - }, "@istanbuljs/load-nyc-config": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.0.0.tgz", @@ -368,9 +355,9 @@ "dev": true }, "@types/crypto-js": { - "version": "3.1.43", - "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-3.1.43.tgz", - "integrity": "sha512-EHe/YKctU3IYNBsDmSOPX/7jLHPRlx8WaiDKSY9JCTnJ8XJeM4c0ZJvx+9Gxmr2s2ihI92R+3U/gNL1sq5oRuQ==" + "version": "3.1.44", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-3.1.44.tgz", + "integrity": "sha512-WOoVHc3gv3zirPQ27BynaOUV9AvWrvPmSF/ZyAAABwb7KYn+iWrEpopW/M9gYMBfNdYHqzvu9AIggwWbt9mGYw==" }, "@types/google-protobuf": { "version": "3.7.2", @@ -394,9 +381,9 @@ "dev": true }, "@types/node": { - "version": "10.17.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.14.tgz", - "integrity": "sha512-G0UmX5uKEmW+ZAhmZ6PLTQ5eu/VPaT+d/tdLd5IFsKRPcbe6lPxocBtcYBFSaLaCW8O60AX90e91Nsp8lVHCNw==" + "version": "10.17.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.18.tgz", + "integrity": "sha512-DQ2hl/Jl3g33KuAUOcMrcAOtsbzb+y/ufakzAdeK9z/H/xsvkpbETZZbPNMIiQuk24f5ZRMCcZIViAwyFIiKmg==" }, "@types/randombytes": { "version": "2.0.0", @@ -482,17 +469,17 @@ }, "dependencies": { "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true } } }, "acorn-walk": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.0.0.tgz", - "integrity": "sha512-7Bv1We7ZGuU79zZbb6rRqcpxo3OY+zrdtloZWoyD8fmGX+FeXRjE+iuGkZjSXLVovLzrsvMGMy0EkwA0E0umxg==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.1.1.tgz", + "integrity": "sha512-wdlPY2tm/9XBr7QkKlq0WQVgiuGTX6YWPyRyBviSoScBuLfTVQhvwg6wJ369GJ/1nPfTLMfnrFIfjqVg6d+jQQ==", "dev": true }, "after": { @@ -787,7 +774,8 @@ "base64-js": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", - "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==", + "dev": true }, "base64id": { "version": "2.0.0", @@ -852,9 +840,9 @@ "dev": true }, "bignumber.js": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz", - "integrity": "sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==" + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" }, "binary-extensions": { "version": "2.0.0", @@ -1100,11 +1088,6 @@ "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", "dev": true }, - "browser-headers": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/browser-headers/-/browser-headers-0.4.1.tgz", - "integrity": "sha512-CA9hsySZVo9371qEHjHZtYxV2cFtVj5Wj/ZHi8ooEsrtm4vOnl9Y9HmyYWk9q+05d7K3rdoAE0j3MVEFVvtQtg==" - }, "browser-pack": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/browser-pack/-/browser-pack-6.1.0.tgz", @@ -1143,9 +1126,9 @@ "dev": true }, "browserify": { - "version": "16.5.0", - "resolved": "https://registry.npmjs.org/browserify/-/browserify-16.5.0.tgz", - "integrity": "sha512-6bfI3cl76YLAnCZ75AGu/XPOsqUhRyc0F/olGIJeCxtfxF2HvPKEcmjU9M8oAPxl4uBY1U7Nry33Q6koV3f2iw==", + "version": "16.5.1", + "resolved": "https://registry.npmjs.org/browserify/-/browserify-16.5.1.tgz", + "integrity": "sha512-EQX0h59Pp+0GtSRb5rL6OTfrttlzv+uyaUVlK6GX3w11SQ0jKPKyjC/54RhPR2ib2KmfcELM06e8FxcI5XNU2A==", "dev": true, "requires": { "JSONStream": "^1.0.3", @@ -1153,7 +1136,7 @@ "browser-pack": "^6.0.1", "browser-resolve": "^1.11.0", "browserify-zlib": "~0.2.0", - "buffer": "^5.0.2", + "buffer": "~5.2.1", "cached-path-relative": "^1.0.0", "concat-stream": "^1.6.0", "console-browserify": "^1.1.0", @@ -1171,7 +1154,7 @@ "inherits": "~2.0.1", "insert-module-globals": "^7.0.0", "labeled-stream-splicer": "^2.0.0", - "mkdirp": "^0.5.0", + "mkdirp-classic": "^0.5.2", "module-deps": "^6.0.0", "os-browserify": "~0.3.0", "parents": "^1.0.1", @@ -1288,9 +1271,9 @@ } }, "buffer": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz", - "integrity": "sha512-zvj65TkFeIt3i6aj5bIvJDzjjQQGs4o/sNoezg1F1kYap9Nu2jcUdpwzRSJTHMMzG0H7bZkn4rNQpImhuxWX2A==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz", + "integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==", "dev": true, "requires": { "base64-js": "^1.0.2", @@ -1842,14 +1825,6 @@ "acorn-node": "^1.6.1", "defined": "^1.0.0", "minimist": "^1.1.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } } }, "diff": { @@ -3266,29 +3241,6 @@ "protobufjs": "^6.8.8" } }, - "grpc-bchrpc-web": { - "version": "0.10.5", - "resolved": "https://registry.npmjs.org/grpc-bchrpc-web/-/grpc-bchrpc-web-0.10.5.tgz", - "integrity": "sha512-4uIA0H6xrnfqBojoGd2kUYZDaXnrVj771Uz9tmJBSdUWuKZdoNwF0kR4Q62WAN1gGpcQS8FyRHzXpzlxuEtEnQ==", - "requires": { - "@improbable-eng/grpc-web": "^0.9.6", - "@improbable-eng/grpc-web-node-http-transport": "^0.12.0", - "@types/google-protobuf": "^3.7.1", - "buffer": "^5.5.0", - "google-protobuf": "^3.2.0" - }, - "dependencies": { - "buffer": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.5.0.tgz", - "integrity": "sha512-9FTEDjLjwoAkEwyMGDjYJQN2gfRgOKBKRfiglhvibGbpeeU/pQn1bJxQqm32OD/AIeEuHxU9roxXxg34Byp/Ww==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - } - } - }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -3485,7 +3437,8 @@ "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==", + "dev": true }, "ignore": { "version": "3.3.10", @@ -4205,20 +4158,26 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "dev": true, "requires": { - "minimist": "0.0.8" + "minimist": "^1.2.5" } }, + "mkdirp-classic": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.2.tgz", + "integrity": "sha512-ejdnDQcR75gwknmMw/tx02AuRs8jCtqFoFqDZMjiNxsu85sRIJVXDKHuLYvUUPRBUtV2FpSZa9bL1BUa3BdR2g==", + "dev": true + }, "mocha": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/mocha/-/mocha-7.1.1.tgz", @@ -5654,6 +5613,14 @@ } } }, + "slp-mdm": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/slp-mdm/-/slp-mdm-0.0.6.tgz", + "integrity": "sha512-fbjlIg/o8OtzgK2JydC6POJp3Qup/rLgy4yB5hoLgxWRlERyJyE29ScwS3r9TTwPxe12qK55pyivAdNOZZXL0A==", + "requires": { + "bignumber.js": "^9.0.0" + } + }, "slp-unit-test-data": { "version": "git+https://github.com/simpleledger/slp-unit-test-data.git#b8f55f7d0c93ce2a51eea1eab3f8f201ca0f6187", "from": "git+https://github.com/simpleledger/slp-unit-test-data.git#b8f55f7d0c93ce2a51eea1eab3f8f201ca0f6187", @@ -5925,9 +5892,9 @@ }, "dependencies": { "readable-stream": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz", - "integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", "dev": true, "requires": { "inherits": "^2.0.3", @@ -6026,14 +5993,6 @@ "dev": true, "requires": { "minimist": "^1.1.0" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } } }, "supports-color": { @@ -6327,9 +6286,9 @@ "dev": true }, "typescript": { - "version": "3.7.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", - "integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==", + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", + "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", "dev": true }, "typescript-tslint-plugin": { diff --git a/package.json b/package.json index 34f6d416..7fe2badf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slpjs", - "version": "0.25.6", + "version": "0.26.0", "description": "Simple Ledger Protocol (SLP) JavaScript Library", "main": "index.js", "files": [ @@ -36,18 +36,18 @@ "devDependencies": { "@istanbuljs/nyc-config-typescript": "^0.1.3", "@types/mocha": "^7.0.2", - "@types/node": "^10.17.14", + "@types/node": "^10.17.18", "bitbox-sdk": "^8.11.2", "bitcoin-rpc-promise": "^2.1.6", "bitcore-lib-cash": "^9.0.0", - "browserify": "^16.5.0", - "mkdirp": "^0.5.1", + "browserify": "^16.5.1", + "mkdirp": "^0.5.5", "mocha": "^7.1.1", "nyc": "^15.0.1", "slp-unit-test-data": "git+https://github.com/simpleledger/slp-unit-test-data.git#b8f55f7d0c93ce2a51eea1eab3f8f201ca0f6187", "source-map-support": "^0.5.16", "ts-node": "^7.0.1", - "typescript": "^3.7.5", + "typescript": "^3.8.3", "typescript-tslint-plugin": "^0.5.5", "uglify-es": "^3.3.9" }, @@ -56,7 +56,7 @@ "bitcore-lib-cash": "^9.0.0" }, "dependencies": { - "@types/crypto-js": "^3.1.43", + "@types/crypto-js": "^3.1.44", "@types/lodash": "^4.14.149", "@types/randombytes": "^2.0.0", "@types/socket.io": "^2.1.2", @@ -64,9 +64,10 @@ "@types/wif": "^2.0.1", "axios": "^0.18.1", "bchaddrjs-slp": "0.2.8", - "bignumber.js": "^8.1.1", + "bignumber.js": "9.0.0", "crypto-js": "^4.0.0", "grpc-bchrpc-node": "0.10.0", - "lodash": "^4.17.15" + "lodash": "^4.17.15", + "slp-mdm": "0.0.6" } } diff --git a/test/slptokentype1.test.ts b/test/slptokentype1.test.ts index 14c0ee37..53bdc154 100644 --- a/test/slptokentype1.test.ts +++ b/test/slptokentype1.test.ts @@ -24,7 +24,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity: any = 100; - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity as BigNumber); }, Error("Amount must be an instance of BigNumber")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity as BigNumber); }, TypeError("bn.isInteger is not a function")); }); it("Throws with initial quantity too large", () => { const ticker: null = null; @@ -34,7 +34,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551616"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Maximum genesis value exceeded. Reduce input quantity below 18446744073709551615.")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("bn outside of range")); }); it("Throws with negative initial quantity", () => { const ticker: null = null; @@ -44,7 +44,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("-1"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Genesis quantity must be greater than 0.")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("bn not positive integer")); }); it("Throws with a decimal initial quantity", () => { const ticker: null = null; @@ -54,7 +54,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("1.1"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Genesis quantity must be a whole number.")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("bn not an integer")); }); it("Throws when allocated OP_RETURN space is exceeded", () => { const ticker = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; @@ -64,7 +64,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Script too long, must be less than 223 bytes.")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Script too long, must be less than or equal to 223 bytes.")); }); it("Succeeds with batonVout is 2 and max inital quantity is used", () => { const ticker = null; @@ -85,9 +85,9 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout = 1; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Baton vout must a number and greater than 1 and less than 256.")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("mintBatonVout out of range (0x02 < > 0xFF)")); }); - it("Throws when batonVout is less than 2", () => { + it("Throws when batonVout is zero", () => { const ticker: null = null; const name: null = null; const documentUri: null = null; @@ -95,9 +95,11 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout = 0; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Baton vout must a number and greater than 1 and less than 256.")); + assert.throws(() => { + SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); + }, Error("mintBatonVout out of range (0x02 < > 0xFF)")); }); - it("Throws when batonVout is less than 2", () => { + it("Throws when batonVout is negative", () => { const ticker: null = null; const name: null = null; const documentUri: null = null; @@ -105,7 +107,15 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout = -1; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Baton vout must a number and greater than 1 and less than 256.")); + // try { + // SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); + // } catch(Err) { + // console.log(Err); + // console.log("done"); + // } + assert.throws(() => { + SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); + }, Error("mintBatonVout out of range (0x02 < > 0xFF)")); }); it("Throws when batonVout is greater than 255", () => { const ticker: null = null; @@ -115,7 +125,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout = 256; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Baton vout must a number and greater than 1 and less than 256.")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("mintBatonVout out of range (0x02 < > 0xFF)")); }); it("Throws when decimals is too high", () => { const ticker: null = null; @@ -125,7 +135,7 @@ describe("SlpTokenType1", () => { const decimals = 10; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Decimals property must be in range 0 to 9")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("decimals out of range")); }); it("Throws when decimals is negative", () => { const ticker: null = null; @@ -135,7 +145,7 @@ describe("SlpTokenType1", () => { const decimals = -1; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Decimals property must be in range 0 to 9")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("decimals out of range")); }); it("Throws when decimals is null", () => { const ticker: null = null; @@ -155,9 +165,9 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity: any = null; - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity as BigNumber); }, Error("Amount must be an instance of BigNumber")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity as BigNumber); }, TypeError("Cannot read property 'isInteger' of null")); }); - it("Throws when documentUri is provided as Buffer", () => { + it("Throws when documentHashHex is provided as Buffer", () => { const ticker: null = null; const name: null = null; const documentUri: null = null; @@ -165,9 +175,9 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex as string, decimals, batonVout, initialQuantity); }, Error("Document hash must be provided as a 64 character hex string")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex as string, decimals, batonVout, initialQuantity); }, Error("documentHash must be either 0 or 32 hex bytes")); }); - it("Throws when documentUri is provided as non-hex string", () => { + it("Throws when documentHashHex is provided as non-hex string", () => { const ticker: null = null; const name: null = null; const documentUri: null = null; @@ -175,7 +185,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("Document hash must be provided as a 64 character hex string")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex, decimals, batonVout, initialQuantity); }, Error("documentHash must be hex")); }); it("Throws when ticker is not a string", () => { const ticker: any = ["a"]; @@ -205,7 +215,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri as string, documentHashHex, decimals, batonVout, initialQuantity); }, Error("documentUri must be a string")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri as string, documentHashHex, decimals, batonVout, initialQuantity); }, TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type number")); }); it("Throws when documentHashHex is not a string", () => { const ticker: null = null; @@ -215,7 +225,7 @@ describe("SlpTokenType1", () => { const decimals = 0; const batonVout: null = null; const initialQuantity = new BigNumber("18446744073709551615"); - assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex as string, decimals, batonVout, initialQuantity); }, Error("Document hash must be provided as a 64 character hex string")); + assert.throws(function () { SlpTokenType1.buildGenesisOpReturn(ticker, name, documentUri, documentHashHex as string, decimals, batonVout, initialQuantity); }, Error("documentHash must be either 0 or 32 hex bytes")); }); }); describe("buildSendOpReturn()", () => { @@ -249,12 +259,12 @@ describe("SlpTokenType1", () => { new BigNumber("66"), new BigNumber("99"), new BigNumber("99"), new BigNumber("99"), new BigNumber("99"), new BigNumber("66"), new BigNumber("99"), new BigNumber("99"), new BigNumber("99"), new BigNumber("99"), new BigNumber("66"), new BigNumber("99"), new BigNumber("99"), new BigNumber("99"), new BigNumber("99") ]; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);} , Error("Cannot have more than 19 SLP token outputs.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);} , Error("too many slp amounts")); }); it("Throws with 0 outputs", () => { const tokenIdHex = "8888888888888888888888888888888888888888888888888888888888888888"; const outputQtyArray: any[] = []; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("Cannot have less than 1 SLP token output.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("send requires at least one amount")); }); it("Throws with null outputs", () => { const tokenIdHex = "8888888888888888888888888888888888888888888888888888888888888888"; @@ -269,27 +279,27 @@ describe("SlpTokenType1", () => { it("Throws with tokenIdHex too short", () => { const tokenIdHex = "88888888888888888888888888888888888888888888888888888888888888"; const outputQtyArray = [ new BigNumber("66") ]; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("tokenIdHex does not pass regex")); }); it("Throws with tokenIdHex too long", () => { const tokenIdHex = "888888888888888888888888888888888888888888888888888888888888888888"; const outputQtyArray = [ new BigNumber("66") ]; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("tokenIdHex does not pass regex")); }); it("Throws with tokenIdHex non-hex string", () => { const tokenIdHex = "zz88888888888888888888888888888888888888888888888888888888888888"; const outputQtyArray = [ new BigNumber("66") ]; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex, outputQtyArray);}, Error("tokenIdHex does not pass regex")); }); it("Throws with tokenIdHex not a string", () => { const tokenIdHex: any = 1; const outputQtyArray = [ new BigNumber("66") ]; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex as string, outputQtyArray);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex as string, outputQtyArray);}, Error("tokenIdHex must be 32 bytes")); }); it("Throws with tokenIdHex not as null", () => { const tokenIdHex: any = null; const outputQtyArray = [ new BigNumber("66") ]; - assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex as string, outputQtyArray);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildSendOpReturn(tokenIdHex as string, outputQtyArray);}, TypeError("Cannot read property 'length' of null")); }); }); describe("buildMintOpReturn()", () => { @@ -314,79 +324,79 @@ describe("SlpTokenType1", () => { const batonVout = 1; const mintQuantity = new BigNumber("66"); //SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity) - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("Baton vout must a number and greater than 1 and less than 256.")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("mintBatonVout out of range (0x02 < > 0xFF)")); }); it("Throws when batonVout is 256", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout = 256; const mintQuantity = new BigNumber("66"); - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("Baton vout must a number and greater than 1 and less than 256.")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("mintBatonVout out of range (0x02 < > 0xFF)")); }); it("Throws when mintQuantity is a number", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout: null = null; const mintQuantity: any = 1; - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity as BigNumber);}, Error("Amount must be an instance of BigNumber")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity as BigNumber);}, TypeError("bn.isInteger is not a function")); }); it("Throws when mintQuantity is null", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout: null = null; const mintQuantity: any = null; - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity as BigNumber);}, Error("Amount must be an instance of BigNumber")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity as BigNumber);}, TypeError("Cannot read property 'isInteger' of null")); }); it("Throws when mintQuantity is too large", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout: null = null; const mintQuantity = new BigNumber("18446744073709551616"); - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("Maximum mint value exceeded. Reduce input quantity below 18446744073709551615.")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("bn outside of range")); }); it("Throws when mintQuantity is negative", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout: null = null; const mintQuantity = new BigNumber("-1"); - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("Mint quantity must be greater than 0.")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("bn not positive integer")); }); it("Throws when mintQuantity is decimal", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout: null = null; const mintQuantity = new BigNumber("1.1"); - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("Mint quantity must be a whole number.")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("bn not an integer")); }); it("Throws when mintQuantity is array", () => { const tokenIdHex = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const batonVout: null = null; const mintQuantity: any = [ new BigNumber("1") ]; - assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity as BigNumber);}, Error("Amount must be an instance of BigNumber")); + assert.throws(() =>{SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity as BigNumber);}, TypeError("bn.isInteger is not a function")); }); it("Throws with tokenIdHex too short", () => { const tokenIdHex = "888888888888888888888888888888888888888888888888888888888888"; const batonVout: null = null; const mintQuantity = new BigNumber("66"); - assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("tokenIdHex does not pass regex")); }); it("Throws with tokenIdHex too long", () => { const tokenIdHex = "888888888888888888888888888888888888888888888888888888888888888888"; const batonVout: null = null; const mintQuantity = new BigNumber("66"); - assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("tokenIdHex does not pass regex")); }); it("Throws with tokenIdHex non-hex string", () => { const tokenIdHex = "zz88888888888888888888888888888888888888888888888888888888888888"; const batonVout: null = null; const mintQuantity = new BigNumber("66"); - assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex, batonVout, mintQuantity);}, Error("tokenIdHex does not pass regex")); }); it("Throws with tokenIdHex not a string", () => { const tokenIdHex: any = 1; const batonVout: null = null; const mintQuantity = new BigNumber("66"); - assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex as string, batonVout, mintQuantity);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex as string, batonVout, mintQuantity);}, Error("tokenIdHex must be 32 bytes")); }); it("Throws with tokenIdHex not as null", () => { const tokenIdHex: any = null; const batonVout: null = null; const mintQuantity = new BigNumber("66"); - assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex as string, batonVout, mintQuantity);}, Error("TokenIdHex must be provided as a 64 character hex string.")); + assert.throws(() => {SlpTokenType1.buildMintOpReturn(tokenIdHex as string, batonVout, mintQuantity);}, TypeError("Cannot read property 'length' of null")); }); }); }); \ No newline at end of file