diff --git a/lib/TokenType1.js b/lib/TokenType1.js index 714bbf4..f1b70de 100644 --- a/lib/TokenType1.js +++ b/lib/TokenType1.js @@ -1,4 +1,8 @@ "use strict"; +/* + This library is concerned with the Token Type 1 defined in this specification: + https://github.com/simpleledger/slp-specifications/blob/master/slp-token-type-1.md +*/ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { @@ -234,6 +238,11 @@ var TokenType1 = /** @class */ (function () { // fundingAddress, tokenReceiverAddress and batonReceiverAddress must be simpleledger format // bchChangeReceiverAddress can be either simpleledger or cashAddr format // validate fundingAddress format + // single fundingAddress + if (config.fundingAddress && !Array.isArray(config.fundingAddress)) { + if (!addy.isSLPAddress(config.fundingAddress)) + throw Error("Token Receiver Address must be simpleledger format"); + } // bulk fundingAddress if (config.fundingAddress && Array.isArray(config.fundingAddress)) { config.fundingAddress.forEach(function (address) { @@ -246,8 +255,10 @@ var TokenType1 = /** @class */ (function () { // validate tokenReceiverAddress format // single tokenReceiverAddress if (config.tokenReceiverAddress && - !addy.isSLPAddress(config.tokenReceiverAddress)) - throw Error("Token Receiver Address must be simpleledger format"); + !Array.isArray(config.tokenReceiverAddress)) { + if (!addy.isSLPAddress(config.tokenReceiverAddress)) + throw Error("Token Receiver Address must be simpleledger format"); + } // bulk tokenReceiverAddress if (config.tokenReceiverAddress && Array.isArray(config.tokenReceiverAddress)) { diff --git a/src/TokenType1.ts b/src/TokenType1.ts index 0d59461..cda57ea 100644 --- a/src/TokenType1.ts +++ b/src/TokenType1.ts @@ -1,3 +1,8 @@ +/* + This library is concerned with the Token Type 1 defined in this specification: + https://github.com/simpleledger/slp-specifications/blob/master/slp-token-type-1.md +*/ + // require deps // imports import { BITBOX } from "bitbox-sdk" @@ -312,6 +317,12 @@ class TokenType1 { // fundingAddress, tokenReceiverAddress and batonReceiverAddress must be simpleledger format // bchChangeReceiverAddress can be either simpleledger or cashAddr format // validate fundingAddress format + // single fundingAddress + + if (config.fundingAddress && !Array.isArray(config.fundingAddress)) { + if (!addy.isSLPAddress(config.fundingAddress)) + throw Error("Token Receiver Address must be simpleledger format") + } // bulk fundingAddress if (config.fundingAddress && Array.isArray(config.fundingAddress)) { @@ -326,9 +337,11 @@ class TokenType1 { // single tokenReceiverAddress if ( config.tokenReceiverAddress && - !addy.isSLPAddress(config.tokenReceiverAddress) - ) - throw Error("Token Receiver Address must be simpleledger format") + !Array.isArray(config.tokenReceiverAddress) + ) { + if (!addy.isSLPAddress(config.tokenReceiverAddress)) + throw Error("Token Receiver Address must be simpleledger format") + } // bulk tokenReceiverAddress if ( diff --git a/test/Utils.js b/test/Utils.js index 5cb9d32..7934753 100644 --- a/test/Utils.js +++ b/test/Utils.js @@ -53,31 +53,25 @@ describe("#Utils", () => { } const list = await SLP.Utils.list() - //console.log(`list: ${JSON.stringify(list, null, 2)}`) + // console.log(`list: ${JSON.stringify(list, null, 2)}`) assert2.isArray(list) - assert2.hasAllKeys(list[0], [ - "blockCreated", - "blockLastActiveMint", - "blockLastActiveSend", - "circulatingSupply", - "containsBaton", - "decimals", - "documentHash", - "documentUri", - "id", - "initialTokenQty", - "mintingBatonStatus", - "name", - "symbol", - "timestamp", - "timestampUnix", - "totalBurned", - "totalMinted", - "txnsSinceGenesis", - "validAddresses", - "versionType" - ]) + + assert2.property(list[0], "decimals") + assert2.property(list[0], "timestamp") + assert2.property(list[0], "versionType") + assert2.property(list[0], "documentUri") + assert2.property(list[0], "symbol") + assert2.property(list[0], "name") + assert2.property(list[0], "containsBaton") + assert2.property(list[0], "id") + assert2.property(list[0], "documentHash") + assert2.property(list[0], "initialTokenQty") + assert2.property(list[0], "blockCreated") + assert2.property(list[0], "totalMinted") + assert2.property(list[0], "totalBurned") + assert2.property(list[0], "circulatingSupply") + assert2.property(list[0], "timestampUnix") }) it(`should list single SLP token by id: 4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84`, async () => { @@ -92,34 +86,28 @@ describe("#Utils", () => { "4276533bb702e7f8c9afd8aa61ebf016e95011dc3d54e55faa847ac1dd461e84" const list = await SLP.Utils.list(tokenId) - //console.log(`list: ${JSON.stringify(list, null, 2)}`) + // console.log(`list: ${JSON.stringify(list, null, 2)}`) + + assert2.property(list, "decimals") + assert2.property(list, "timestamp") + assert2.property(list, "versionType") + assert2.property(list, "documentUri") + assert2.property(list, "symbol") + assert2.property(list, "name") + assert2.property(list, "containsBaton") + assert2.property(list, "id") + assert2.property(list, "documentHash") + assert2.property(list, "initialTokenQty") + assert2.property(list, "blockCreated") + assert2.property(list, "totalMinted") + assert2.property(list, "totalBurned") + assert2.property(list, "circulatingSupply") + assert2.property(list, "timestampUnix") - assert2.hasAllKeys(list, [ - "blockCreated", - "blockLastActiveMint", - "blockLastActiveSend", - "circulatingSupply", - "containsBaton", - "decimals", - "documentHash", - "documentUri", - "id", - "initialTokenQty", - "mintingBatonStatus", - "name", - "symbol", - "timestamp", - "timestampUnix", - "totalBurned", - "totalMinted", - "txnsSinceGenesis", - "validAddresses", - "versionType" - ]) assert.equal(list.id, tokenId) }) - it(`should list multople SLP tokens by array of ids`, async () => { + it(`should list multiple SLP tokens by array of ids`, async () => { // Mock the call to rest.bitcoin.com if (process.env.TEST === "unit") { nock(SERVER) @@ -135,28 +123,22 @@ describe("#Utils", () => { const list = await SLP.Utils.list(tokenIds) // console.log(`list: ${JSON.stringify(list, null, 2)}`) - assert2.hasAllKeys(list[0], [ - "blockCreated", - "blockLastActiveMint", - "blockLastActiveSend", - "circulatingSupply", - "containsBaton", - "decimals", - "documentHash", - "documentUri", - "id", - "initialTokenQty", - "mintingBatonStatus", - "name", - "symbol", - "timestamp", - "timestampUnix", - "totalBurned", - "totalMinted", - "txnsSinceGenesis", - "validAddresses", - "versionType" - ]) + assert2.property(list[0], "decimals") + assert2.property(list[0], "timestamp") + assert2.property(list[0], "versionType") + assert2.property(list[0], "documentUri") + assert2.property(list[0], "symbol") + assert2.property(list[0], "name") + assert2.property(list[0], "containsBaton") + assert2.property(list[0], "id") + assert2.property(list[0], "documentHash") + assert2.property(list[0], "initialTokenQty") + assert2.property(list[0], "blockCreated") + assert2.property(list[0], "totalMinted") + assert2.property(list[0], "totalBurned") + assert2.property(list[0], "circulatingSupply") + assert2.property(list[0], "timestampUnix") + assert.equal(list[0].id, tokenIds[0]) }) }) diff --git a/test/e2e/util/e2e-util.js b/test/e2e/util/e2e-util.js index c646fb9..f81e764 100644 --- a/test/e2e/util/e2e-util.js +++ b/test/e2e/util/e2e-util.js @@ -14,7 +14,7 @@ const SLPSDK = require("../../../lib/SLP") const slpsdk = new SLPSDK() const TEST_TOKEN_ID = - "f3fcb5eb95bb02e0532952ac4f209c55c8022ae24979a1c4098dd171a2a28b78" + "f16b1a32f0e7fc7f2c55e787e6b16461af1350c6b5070875606e30ba11f123a1" // Open a wallet and return an object with its address, BCH balance, and SLP // token balance. @@ -22,11 +22,11 @@ async function openWallet(filename) { try { walletInfo = require(filename) - //const walletBalance = await getBalance(walletInfo) + // const walletBalance = await getBalance(walletInfo) // const walletBalance = await slpsdk.Utils.balancesForAddress( // walletInfo.slpAddress // ) - // // console.log(`walletBalance: ${JSON.stringify(walletBalance, null, 2)}`) + // console.log(`walletBalance: ${JSON.stringify(walletBalance, null, 2)}`) // walletInfo.tokenBalance = walletBalance return walletInfo diff --git a/test/fixtures/mock-utils.js b/test/fixtures/mock-utils.js index 2da42d9..879d803 100644 --- a/test/fixtures/mock-utils.js +++ b/test/fixtures/mock-utils.js @@ -5,54 +5,43 @@ const mockList = [ { decimals: 0, - timestamp: "2019-04-29 08:59", - timestampUnix: 1539218362, + timestamp: "2019-02-02 00:09:12", versionType: 1, documentUri: "", - symbol: "WMW", - name: "WheresMyWallet", - containsBaton: false, - id: "8fc284dcbc922f7bb7e2a443dc3af792f52923bba403fcf67ca028c88e89da0e", + symbol: "LVL032", + name: "Lode Runner Level 32 Resume", + containsBaton: true, + id: "3641fc50120b604e4020ab8930f10f687b886db4280fb94a35f25ef4b891bb49", documentHash: null, - initialTokenQty: 1000, - blockCreated: 580336, - blockLastActiveSend: 580336, - blockLastActiveMint: null, - txnsSinceGenesis: 1, - validAddresses: 1, - totalMinted: 1000, - totalBurned: 0, - circulatingSupply: 1000, - mintingBatonStatus: "NEVER_CREATED" + initialTokenQty: 0, + blockCreated: 574388, + totalMinted: null, + totalBurned: null, + circulatingSupply: null, + timestampUnix: 1549066152 }, { - decimals: 0, - timestamp: "2019-04-29 08:59", - timestampUnix: 1539218362, + decimals: 8, + timestamp: "2019-02-01 23:32:48", versionType: 1, - documentUri: "", - symbol: "WMW", - name: "Where'sMyWallet", + documentUri: "SloppyChikun.cash", + symbol: "CHIKUN", + name: "Sloppy Chikun", containsBaton: false, - id: "471d1f33e8a69cf59ce174ce43174feeecdf1f475ccc4cc3705600a5d6d2cd06", + id: "3cc09f707c6ca0c9dcb6b3df6e5df6d6d1e49864fa0948d5f744648f1f2ee865", documentHash: null, - initialTokenQty: 1000, - blockCreated: 580336, - blockLastActiveSend: 580351, - blockLastActiveMint: null, - txnsSinceGenesis: 2, - validAddresses: 2, - totalMinted: 1000, - totalBurned: 0, - circulatingSupply: 1000, - mintingBatonStatus: "NEVER_CREATED" + initialTokenQty: 84000000, + blockCreated: 574387, + totalMinted: null, + totalBurned: null, + circulatingSupply: null, + timestampUnix: 1549063968 } ] const mockToken = { decimals: 0, - timestamp: "2018-08-25 01:54", - timestampUnix: 1539218362, + timestamp: "2018-07-06 01:54:35", versionType: 1, documentUri: "", symbol: "USDT", @@ -62,21 +51,16 @@ const mockToken = { documentHash: null, initialTokenQty: 10000000000000000, blockCreated: 544903, - blockLastActiveSend: 544905, - blockLastActiveMint: null, - txnsSinceGenesis: 3, - validAddresses: 0, - totalMinted: 10000000000000000, - totalBurned: 10000000000000000, - circulatingSupply: 0, - mintingBatonStatus: "NEVER_CREATED" + totalMinted: null, + totalBurned: null, + circulatingSupply: null, + timestampUnix: 1530842075 } const mockTokens = [ { decimals: 0, - timestamp: "2018-08-25 01:54", - timestampUnix: 1539218362, + timestamp: "2018-07-06 01:54:35", versionType: 1, documentUri: "", symbol: "USDT", @@ -86,36 +70,14 @@ const mockTokens = [ documentHash: null, initialTokenQty: 10000000000000000, blockCreated: 544903, - blockLastActiveSend: 544905, - blockLastActiveMint: null, - txnsSinceGenesis: 3, - validAddresses: 0, - totalMinted: 10000000000000000, - totalBurned: 10000000000000000, - circulatingSupply: 0, - mintingBatonStatus: "NEVER_CREATED" + totalMinted: null, + totalBurned: null, + circulatingSupply: null, + timestampUnix: 1530842075 }, { - decimals: 0, - timestamp: "2019-04-29 08:59", - timestampUnix: 1539218362, - versionType: 1, - documentUri: "", - symbol: "WMW", - name: "Where'sMyWallet", - containsBaton: false, - id: "471d1f33e8a69cf59ce174ce43174feeecdf1f475ccc4cc3705600a5d6d2cd06", - documentHash: null, - initialTokenQty: 1000, - blockCreated: 580336, - blockLastActiveSend: 580351, - blockLastActiveMint: null, - txnsSinceGenesis: 2, - validAddresses: 2, - totalMinted: 1000, - totalBurned: 0, - circulatingSupply: 1000, - mintingBatonStatus: "NEVER_CREATED" + id: "b3f4f132dc3b9c8c96316346993a8d54d729715147b7b11aa6c8cd909e955313", + valid: false } ]