Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
node_modules
package-lock.json
release/docs
release/docs
.vscode
.idea
11 changes: 10 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"type": "module",
"scripts": {
"test": "mocha ./**/*.test.js"
},
"dependencies": {
"@xrplkit/book": "file:../book",
"@xrplkit/simulate": "file:../simulate",
"@xrplkit/socket": "file:../socket",
"@xrplkit/xfl": "file:../xfl"
"@xrplkit/xfl": "file:../xfl",
"@xrplkit/xls26": "file:../xls26",
"@xrplkit/xls89": "file:../xls89"
},
"devDependencies": {
"chai": "6.2.0",
"mocha": "11.7.3"
}
}
67 changes: 67 additions & 0 deletions tests/xls26/fixtures/ioumetadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"name": "valid metadata as per xls26",
"input": "[[ISSUERS]]\naddress = \"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De\"\nname = \"Ripple\"\ndesc = \"We're building the Internet of Value.\"\n\n[[TOKENS]]\nissuer = \"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De\"\ncurrency = \"RLUSD\"\nname = \"Ripple USD\"\ndesc = \"Ripple USD (RLUSD) is natively issued on the XRP Ledger and Ethereum blockchains and is enabled with a number of features to ensure strict adherence to compliance standards, flexibility for developers, and security for holders.\"\nicon = \"https://ripple.com/assets/rlusd-logo.png\"\nasset_class = \"rwa\"\nasset_subclass = \"stablecoin\"\n\n[[TOKENS.URLS]]\nurl = \"https://ripple.com\"\ntype = \"website\"\ntitle = \"Official Website\"\n\n[[TOKENS.URLS]]\nurl = \"https://x.com/ripple\"\ntype = \"social\"",
"output": {
"issuers": [
{
"address": "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",
"name": "Ripple",
"desc": "We're building the Internet of Value."
}
],
"tokens": [
{
"issuer": "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",
"currency": "RLUSD",
"name": "Ripple USD",
"desc": "Ripple USD (RLUSD) is natively issued on the XRP Ledger and Ethereum blockchains and is enabled with a number of features to ensure strict adherence to compliance standards, flexibility for developers, and security for holders.",
"icon": "https://ripple.com/assets/rlusd-logo.png",
"asset_class": "rwa",
"asset_subclass": "stablecoin",
"urls": [
{
"url": "https://ripple.com",
"type": "website",
"title": "Official Website"
},
{
"url": "https://x.com/ripple",
"type": "social"
}
]
}
],
"issues": []
}
},
{
"name": "missing required fields",
"input": "[[ISSUERS]]\ndesc = \"We're building the Internet of Value.\"\n\n[[TOKENS]]\nissuer = \"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De\"\ncurrency = \"RLUSD\"\n\ndesc = \"Ripple USD (RLUSD) is natively issued on the XRP Ledger and Ethereum blockchains and is enabled with a number of features to ensure strict adherence to compliance standards, flexibility for developers, and security for holders.\"\nicon = \"https://ripple.com/assets/rlusd-logo.png\"\nasset_class = \"rwa\"\nasset_subclass = \"stablecoin\"\n\n[[TOKENS.URLS]]\nurl = \"https://ripple.com\"\ntype = \"website\"\ntitle = \"Official Website\"\n\n[[TOKENS.URLS]]\nurl = \"https://x.com/ripple\"\ntype = \"social\"",
"output": {
"issuers": [],
"tokens": [
{
"issuer": "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",
"currency": "RLUSD",
"desc": "Ripple USD (RLUSD) is natively issued on the XRP Ledger and Ethereum blockchains and is enabled with a number of features to ensure strict adherence to compliance standards, flexibility for developers, and security for holders.",
"icon": "https://ripple.com/assets/rlusd-logo.png",
"asset_class": "rwa",
"asset_subclass": "stablecoin",
"urls": [
{
"url": "https://ripple.com",
"type": "website",
"title": "Official Website"
},
{
"url": "https://x.com/ripple",
"type": "social"
}
]
}
],
"issues": ["[[ISSUERS]] address field missing: skipping stanza"]
}
}
]
35 changes: 35 additions & 0 deletions tests/xls26/fixtures/trustlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"name": "both mpt and iou tokens",
"input": "[[TOKENS]]\nmpt_issuance_id = \"000525D8BE61F040420DB5A4CBA0577A70E6BD013E75E00\"\ntrust_level = 2\n[[TOKENS]]\nissuer = \"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De\"\ncurrency = \"RLUSD\"\nname = \"Ripple USD\"\ndesc = \"Ripple USD (RLUSD) is natively issued on the XRP Ledger and Ethereum blockchains and is enabled with a number of features to ensure strict adherence to compliance standards, flexibility for developers, and security for holders.\"\nicon = \"https://ripple.com/assets/rlusd-logo.png\"\nasset_class = \"rwa\"\nasset_subclass = \"stablecoin\"\n\n[[TOKENS.URLS]]\nurl = \"https://ripple.com\"\ntype = \"website\"\ntitle = \"Official Website\"\n\n[[TOKENS.URLS]]\nurl = \"https://x.com/ripple\"\ntype = \"social\"",
"output": {
"issuers": [],
"tokens": [
{
"issuer": "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",
"currency": "RLUSD",
"name": "Ripple USD",
"desc": "Ripple USD (RLUSD) is natively issued on the XRP Ledger and Ethereum blockchains and is enabled with a number of features to ensure strict adherence to compliance standards, flexibility for developers, and security for holders.",
"icon": "https://ripple.com/assets/rlusd-logo.png",
"asset_class": "rwa",
"asset_subclass": "stablecoin",
"urls": [
{
"url": "https://ripple.com",
"type": "website",
"title": "Official Website"
},
{
"url": "https://x.com/ripple",
"type": "social"
}
]
}
],
"issues": [
"[[TOKENS]] mpt_issuance_id field: is not a valid mpt_issuance_id",
"[[TOKENS]] mpt_issuance_id field missing: skipping stanza"
]
}
}
]
41 changes: 41 additions & 0 deletions tests/xls26/xls26.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { assert } from 'chai'
import { parse } from '@xrplkit/xls26'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const iouFixtures = JSON.parse(
fs.readFileSync(__dirname + '/fixtures/ioumetadata.json', 'utf8')
)
const trustlistFixtures = JSON.parse(
fs.readFileSync(__dirname + '/fixtures/trustlists.json', 'utf8')
)

describe('XLS-26 parse method - IOU tokens', () => {
iouFixtures.forEach((test, index) => {
const testName = test.name || `Test Case #${index + 1}`
it(`${testName}`, () => {
const expectedOutput = test.output
const result = parse(test.input)

assert.sameMembers(result.issues, expectedOutput.issues)
assert.deepStrictEqual(result.issuers, expectedOutput.issuers)
assert.deepStrictEqual(result.tokens, expectedOutput.tokens)
})
})
})

describe('XLS-26 parse method - trustlist', () => {
trustlistFixtures.forEach((test, index) => {
const testName = test.name || `Test Case #${index + 1}`
it(`${testName}`, () => {
const expectedOutput = test.output
const result = parse(test.input)

assert.sameMembers(result.issues, expectedOutput.issues)
assert.deepStrictEqual(result.issuers, expectedOutput.issuers)
assert.deepStrictEqual(result.tokens, expectedOutput.tokens)
})
})
})
112 changes: 112 additions & 0 deletions tests/xls89/fixtures/mptmetadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"name": "valid short metadata",
"MPTokenMetadata": "7B0A20202274223A20225442494C4C222C0A2020226E223A2022542D42696C6C205969656C6420546F6B656E222C0A20202264223A202241207969656C642D62656172696E6720737461626C65636F696E206261636B65642062792073686F72742D7465726D20552E532E205472656173757269657320616E64206D6F6E6579206D61726B657420696E737472756D656E74732E222C0A20202269223A20226578616D706C652E6F72672F7462696C6C2D69636F6E2E706E67222C0A2020226163223A2022727761222C0A2020226173223A20227472656173757279222C0A202022696E223A20224578616D706C65205969656C6420436F2E222C0A2020227573223A205B0A202020207B0A2020202020202275223A20226578616D706C657969656C642E636F2F7462696C6C222C0A2020202020202263223A202277656273697465222C0A2020202020202274223A202250726F647563742050616765220A202020207D2C0A202020207B0A2020202020202275223A20226578616D706C657969656C642E636F2F646F6373222C0A2020202020202263223A2022646F6373222C0A2020202020202274223A20225969656C6420546F6B656E20446F6373220A202020207D0A20205D2C0A2020226169223A207B0A2020202022696E7465726573745F72617465223A2022352E303025222C0A2020202022696E7465726573745F74797065223A20227661726961626C65222C0A20202020227969656C645F736F75726365223A2022552E532E2054726561737572792042696C6C73222C0A20202020226D617475726974795F64617465223A2022323034352D30362D3330222C0A20202020226375736970223A2022393132373936525830220A20207D0A7D",
"output": {
"token": {
"ticker": "TBILL",
"name": "T-Bill Yield Token",
"desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.",
"icon": "https://example.org/tbill-icon.png",
"asset_class": "rwa",
"asset_subclass": "treasury",
"issuer_name": "Example Yield Co.",
"uris": [
{
"uri": "https://exampleyield.co/tbill",
"category": "website",
"title": "Product Page"
},
{
"uri": "https://exampleyield.co/docs",
"category": "docs",
"title": "Yield Token Docs"
}
],
"additional_info": {
"interest_rate": "5.00%",
"interest_type": "variable",
"yield_source": "U.S. Treasury Bills",
"maturity_date": "2045-06-30",
"cusip": "912796RX0"
}
},
"issues": []
}
},
{
"name": "valid long metadata",
"MPTokenMetadata": "7B227469636B6572223A225442494C4C222C226E616D65223A22542D42696C6C205969656C6420546F6B656E222C2264657363223A2241207969656C642D62656172696E6720737461626C65636F696E206261636B65642062792073686F72742D7465726D20552E532E205472656173757269657320616E64206D6F6E6579206D61726B657420696E737472756D656E74732E222C2269636F6E223A2268747470733A2F2F6578616D706C652E6F72672F7462696C6C2D69636F6E2E706E67222C2261737365745F636C617373223A22727761222C2261737365745F737562636C617373223A227472656173757279222C226973737565725F6E616D65223A224578616D706C65205969656C6420436F2E222C2275726973223A5B7B22757269223A2268747470733A2F2F6578616D706C657969656C642E636F2F7462696C6C222C2263617465676F7279223A2277656273697465222C227469746C65223A2250726F647563742050616765227D2C7B22757269223A2268747470733A2F2F6578616D706C657969656C642E636F2F646F6373222C2263617465676F7279223A22646F6373222C227469746C65223A225969656C6420546F6B656E20446F6373227D5D2C226164646974696F6E616C5F696E666F223A7B22696E7465726573745F72617465223A22352E303025222C22696E7465726573745F74797065223A227661726961626C65222C227969656C645F736F75726365223A22552E532E2054726561737572792042696C6C73222C226D617475726974795F64617465223A22323034352D30362D3330222C226375736970223A22393132373936525830227D7D",
"output": {
"token": {
"ticker": "TBILL",
"name": "T-Bill Yield Token",
"desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.",
"icon": "https://example.org/tbill-icon.png",
"asset_class": "rwa",
"asset_subclass": "treasury",
"issuer_name": "Example Yield Co.",
"uris": [
{
"uri": "https://exampleyield.co/tbill",
"category": "website",
"title": "Product Page"
},
{
"uri": "https://exampleyield.co/docs",
"category": "docs",
"title": "Yield Token Docs"
}
],
"additional_info": {
"interest_rate": "5.00%",
"interest_type": "variable",
"yield_source": "U.S. Treasury Bills",
"maturity_date": "2045-06-30",
"cusip": "912796RX0"
}
},
"issues": []
}
},
{
"name": "missing required field",
"MPTokenMetadata": "7B2264657363223A2241207969656C642D62656172696E6720737461626C65636F696E206261636B65642062792073686F72742D7465726D20552E532E205472656173757269657320616E64206D6F6E6579206D61726B657420696E737472756D656E74732E222C2269636F6E223A2268747470733A2F2F6578616D706C652E6F72672F7462696C6C2D69636F6E2E706E67222C2261737365745F636C617373223A22727761222C2261737365745F737562636C617373223A227472656173757279222C226973737565725F6E616D65223A224578616D706C65205969656C6420436F2E222C2275726973223A5B7B2263617465676F7279223A2277656273697465222C227469746C65223A2250726F647563742050616765227D2C7B22757269223A2268747470733A2F2F6578616D706C657969656C642E636F2F646F6373222C2263617465676F7279223A22646F6373222C227469746C65223A225969656C6420546F6B656E20446F6373227D5D2C226164646974696F6E616C5F696E666F223A7B22696E7465726573745F72617465223A22352E303025222C22696E7465726573745F74797065223A227661726961626C65222C227969656C645F736F75726365223A22552E532E2054726561737572792042696C6C73222C226D617475726974795F64617465223A22323034352D30362D3330222C226375736970223A22393132373936525830227D7D",
"output": {
"token": {},
"issues": [
"Token - ticker field missing: skipping object",
"Token - name field missing: skipping object"
]
}
},
{
"name": "empty additional_info",
"MPTokenMetadata": "7B227469636B6572223A225442494C4C222C226E616D65223A22542D42696C6C205969656C6420546F6B656E222C2264657363223A2241207969656C642D62656172696E6720737461626C65636F696E206261636B65642062792073686F72742D7465726D20552E532E205472656173757269657320616E64206D6F6E6579206D61726B657420696E737472756D656E74732E222C2269636F6E223A2268747470733A2F2F6578616D706C652E6F72672F7462696C6C2D69636F6E2E706E67222C2261737365745F636C617373223A22727761222C2261737365745F737562636C617373223A227472656173757279222C226973737565725F6E616D65223A224578616D706C65205969656C6420436F2E222C2275726973223A5B7B22757269223A2268747470733A2F2F6578616D706C657969656C642E636F2F7462696C6C222C2263617465676F7279223A2277656273697465222C227469746C65223A2250726F647563742050616765227D2C7B22757269223A2268747470733A2F2F6578616D706C657969656C642E636F2F646F6373222C2263617465676F7279223A22646F6373222C227469746C65223A225969656C6420546F6B656E20446F6373227D5D2C226164646974696F6E616C5F696E666F223A22227D",
"output": {
"token": {
"ticker": "TBILL",
"name": "T-Bill Yield Token",
"desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.",
"icon": "https://example.org/tbill-icon.png",
"asset_class": "rwa",
"asset_subclass": "treasury",
"issuer_name": "Example Yield Co.",
"uris": [
{
"uri": "https://exampleyield.co/tbill",
"category": "website",
"title": "Product Page"
},
{
"uri": "https://exampleyield.co/docs",
"category": "docs",
"title": "Yield Token Docs"
}
],
"additional_info": ""
},
"issues": []
}
}
]
23 changes: 23 additions & 0 deletions tests/xls89/xls89.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { assert } from 'chai'
import { parse } from '@xrplkit/xls89'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const fixtures = JSON.parse(
fs.readFileSync(__dirname + '/fixtures/mptmetadata.json', 'utf8')
)

describe('XLS-89 parse method', () => {
fixtures.forEach((test, index) => {
const testName = test.name || `Test Case #${index + 1}`
it(`${testName}`, () => {
const expectedOutput = test.output
const result = parse(test.MPTokenMetadata)

assert.sameMembers(result.issues, expectedOutput.issues)
assert.deepStrictEqual(result.token, expectedOutput.token)
})
})
})
26 changes: 24 additions & 2 deletions xls26/xls26.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const issuerFields = [
}
]

const tokenFields = [
const iouTokenFields = [
{
key: 'currency',
alternativeKeys: ['code'],
Expand Down Expand Up @@ -171,6 +171,28 @@ const tokenFields = [
}
]

const mpTokenFields = [
{
key: 'mpt_issuance_id',
required: true,
validate: v => {
if(!/^[0-9a-fA-F]{48}$/.test(v))
throw 'is not a valid mpt_issuance_id'
}
},
{
key: 'trust_level',
required: true,
validate: v => {
if(v !== parseInt(v))
throw 'must be a integer'

if(v < 0 || v > 3)
throw 'must be between 0 and 3'
}
}
]

const urlFields = [
{
key: 'url',
Expand Down Expand Up @@ -271,7 +293,7 @@ export function parse(str){
}

for(let stanza of (toml.TOKENS || toml.CURRENCIES || [])){
let { valid, parsed: token, issues: tokenIssues } = parseStanza(stanza, tokenFields)
let { valid, parsed: token, issues: tokenIssues } = parseStanza(stanza, stanza['mpt_issuance_id'] != null ? mpTokenFields : iouTokenFields)

issues.push(
...tokenIssues.map(
Expand Down
Loading