Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/TokenType1.js
Original file line number Diff line number Diff line change
@@ -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++) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down
19 changes: 16 additions & 3 deletions src/TokenType1.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)) {
Expand All @@ -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 (
Expand Down
120 changes: 51 additions & 69 deletions test/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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)
Expand All @@ -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])
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/util/e2e-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ 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.
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
Expand Down
108 changes: 35 additions & 73 deletions test/fixtures/mock-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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
}
]

Expand Down