diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ceaeb6a4d3..08de2ac56e 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -3,20 +3,22 @@
/.github/ @fuxingloh
/.husky/ @fuxingloh
-/.idea/ @fuxingloh
-/.github/workflows/oss-governance-bot.yml @fuxingloh
-/.github/governance.yml @fuxingloh
+/.idea/ @fuxingloh @jingyi2811 @thedoublejay
-/website/ @fuxingloh
+/website/ @fuxingloh @canonbrother
/packages/jellyfish/ @fuxingloh
/packages/jellyfish-address/ @fuxingloh @ivan-zynesis
-/packages/jellyfish-api-core/ @fuxingloh @canonbrother @jingyi2811
-/packages/jellyfish-api-jsonrpc/ @fuxingloh
+/packages/jellyfish-api-core/ @fuxingloh @canonbrother @jingyi2811 @thedoublejay
+/packages/jellyfish-api-jsonrpc/ @fuxingloh @thedoublejay
/packages/jellyfish-crypto/ @fuxingloh
/packages/jellyfish-json/ @fuxingloh @canonbrother
/packages/jellyfish-network/ @fuxingloh
-/packages/jellyfish-transaction/ @fuxingloh
+
+/packages/jellyfish-transaction/ @fuxingloh
+/packages/jellyfish-transaction/src/script/ @fuxingloh @canonbrother @jingyi2811
+/packages/jellyfish-transaction/src/script/defi/ @fuxingloh @canonbrother
+
/packages/jellyfish-transaction-builder/ @fuxingloh @ivan-zynesis
/packages/jellyfish-wallet/ @fuxingloh
/packages/jellyfish-wallet-mnemonic/ @fuxingloh
@@ -29,6 +31,6 @@ jest.config.js @fuxingloh
package.json @fuxingloh
package-lock.json @fuxingloh
-CONTRIBUTING.md @fuxingloh
+CONTRIBUTING.md @fuxingloh @canonbrother
README.md @fuxingloh
LICENSE @fuxingloh
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f30e25eb33..c7274f31b9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,8 +11,8 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2.3.4
- - uses: actions/setup-node@v2.1.5
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
+ - uses: actions/setup-node@46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea
with:
node-version: '15'
@@ -26,8 +26,8 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2.3.4
- - uses: actions/setup-node@v2.1.5
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
+ - uses: actions/setup-node@46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea
with:
node-version: '15'
@@ -39,8 +39,8 @@ jobs:
name: Size Limit
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2.3.4
- - uses: actions/setup-node@v2.1.5
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
+ - uses: actions/setup-node@46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea
with:
node-version: '15'
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index ee5a2877bd..8b77f370fd 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -1,8 +1,6 @@
-name: "CodeQL"
+name: CodeQL
on:
- push:
- branches: [ main ]
pull_request:
branches: [ main ]
schedule:
@@ -19,8 +17,7 @@ jobs:
language: [ javascript ]
steps:
- - name: Checkout repository
- uses: actions/checkout@v2.3.4
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
diff --git a/.github/workflows/oss-governance-bot.yml b/.github/workflows/oss-governance-bot.yml
index 13dab3f741..c4b30da564 100644
--- a/.github/workflows/oss-governance-bot.yml
+++ b/.github/workflows/oss-governance-bot.yml
@@ -1,8 +1,7 @@
-name: OSS
+name: Governance
on:
pull_request_target:
- branches: [ master, main ]
types: [ synchronize, opened, labeled, unlabeled ]
issues:
types: [ opened, labeled, unlabeled ]
@@ -11,10 +10,10 @@ on:
jobs:
main:
- name: Governance
+ name: OSS
runs-on: ubuntu-latest
steps:
- - uses: DeFiCh/oss-governance-bot@v2.0.5
+ - uses: DeFiCh/oss-governance-bot@833b5984684295040d750c1970d05dc8beaa8724
with:
github-token: ${{ secrets.DEFICHAIN_BOT_GITHUB_TOKEN }}
diff --git a/.github/workflows/oss-governance-labeler.yml b/.github/workflows/oss-governance-labeler.yml
index 9b4726d673..92e31bff26 100644
--- a/.github/workflows/oss-governance-labeler.yml
+++ b/.github/workflows/oss-governance-labeler.yml
@@ -10,7 +10,7 @@ jobs:
name: Labeler
runs-on: ubuntu-latest
steps:
- - uses: fuxingloh/multi-labeler@v1.5.1
+ - uses: fuxingloh/multi-labeler@1d6d95ddcc7ef8b928d514329663ba4e0ff0eaf5
with:
github-token: ${{ secrets.DEFICHAIN_BOT_GITHUB_TOKEN }}
config-path: .github/labeler.yml
diff --git a/.github/workflows/oss-governance-project-issue.yml b/.github/workflows/oss-governance-project-issue.yml
new file mode 100644
index 0000000000..3803a09583
--- /dev/null
+++ b/.github/workflows/oss-governance-project-issue.yml
@@ -0,0 +1,21 @@
+name: Governance
+
+on:
+ issues:
+ types: [ opened, labeled ]
+
+jobs:
+ main:
+ name: DeFi Products
+ runs-on: ubuntu-latest
+ if: contains(github.event.issue.labels.*.name, 'triage/accepted')
+ steps:
+ - uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293
+ with:
+ github-token: ${{ secrets.DEFICHAIN_BOT_GITHUB_TOKEN }}
+ script: |
+ github.projects.createCard({
+ column_id: 13687171,
+ content_id: context.payload.issue.id,
+ content_type: 'Issue',
+ })
diff --git a/.github/workflows/oss-governance-project-pr.yml b/.github/workflows/oss-governance-project-pr.yml
new file mode 100644
index 0000000000..3066aa0e47
--- /dev/null
+++ b/.github/workflows/oss-governance-project-pr.yml
@@ -0,0 +1,28 @@
+name: Governance
+
+on:
+ pull_request:
+ types: [ opened ]
+
+jobs:
+ main:
+ name: DeFi Products
+ runs-on: ubuntu-latest
+ if: github.event.sender.type == 'User' && github.event.pull_request.head.repo.full_name == github.repository
+ steps:
+ - uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293
+ with:
+ github-token: ${{ secrets.DEFICHAIN_BOT_GITHUB_TOKEN }}
+ script: |
+ github.projects.createCard({
+ column_id: 14389251,
+ content_id: context.payload.pull_request.id,
+ content_type: 'PullRequest',
+ })
+
+ github.issues.addAssignees({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.issue.number,
+ assignees: [context.payload.sender.login]
+ })
diff --git a/.github/workflows/oss-governance-project.yml b/.github/workflows/oss-governance-project.yml
deleted file mode 100644
index cbb6ba1962..0000000000
--- a/.github/workflows/oss-governance-project.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-name: Projects
-
-on:
- pull_request:
- types:
- - opened
- - ready_for_review
-
-jobs:
- main:
- name: DeFi Products
- runs-on: ubuntu-latest
- steps:
- - uses: takanabe/github-actions-automate-projects@5d004c140c65fa8b4ef3b18a38219ce680bce816
- if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
- env:
- GITHUB_TOKEN: ${{ secrets.DEFICHAIN_BOT_GITHUB_TOKEN }}
- GITHUB_PROJECT_URL: https://github.com/orgs/DeFiCh/projects/1
- GITHUB_PROJECT_COLUMN_NAME: In progress
diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml
index ae3051fcd1..7d4a34c19e 100644
--- a/.github/workflows/release-publish.yml
+++ b/.github/workflows/release-publish.yml
@@ -10,12 +10,12 @@ jobs:
runs-on: ubuntu-latest
environment: NPM Release Publishing
steps:
- - uses: actions/checkout@v2.3.4
- - uses: actions/setup-node@v2.1.5
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
+ - uses: actions/setup-node@46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea
with:
node-version: '15'
- - uses: actions/github-script@v4.0.2
+ - uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293
id: version
with:
script: |
diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml
index 01df26ca82..8d857ce605 100644
--- a/.github/workflows/sync-labels.yml
+++ b/.github/workflows/sync-labels.yml
@@ -1,4 +1,4 @@
-name: sync labels
+name: Labels
on:
push:
@@ -7,9 +7,10 @@ on:
jobs:
main:
+ name: Syncer
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2.3.4
+ - uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
- uses: micnncim/action-label-syncer@0e9c5104859d0e78219af63791636eba42382b5d
with:
diff --git a/.idea/dictionaries/fuxing.xml b/.idea/dictionaries/fuxing.xml
index 189be9e5a6..41c62832d5 100644
--- a/.idea/dictionaries/fuxing.xml
+++ b/.idea/dictionaries/fuxing.xml
@@ -199,6 +199,7 @@
walletversion
wpkh
wtxid
+ zynesis
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 2e1557c554..92dc81a22e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -29428,6 +29428,7 @@
"@defichain/jellyfish-transaction": "0.0.0"
},
"devDependencies": {
+ "@defichain/jellyfish-api-jsonrpc": "0.0.0",
"@defichain/testcontainers": "0.0.0",
"@defichain/testing": "0.0.0"
},
@@ -30705,6 +30706,7 @@
"@defichain/jellyfish-transaction-builder": {
"version": "file:packages/jellyfish-transaction-builder",
"requires": {
+ "@defichain/jellyfish-api-jsonrpc": "0.0.0",
"@defichain/jellyfish-crypto": "0.0.0",
"@defichain/jellyfish-transaction": "0.0.0",
"@defichain/testcontainers": "0.0.0",
diff --git a/packages/jellyfish-address/__tests__/p2pkh.test.ts b/packages/jellyfish-address/__tests__/p2pkh.test.ts
index a3d1da6997..51abde4820 100644
--- a/packages/jellyfish-address/__tests__/p2pkh.test.ts
+++ b/packages/jellyfish-address/__tests__/p2pkh.test.ts
@@ -27,23 +27,23 @@ describe('P2PKH', () => {
it('should get the type precisely', () => {
const p2pkh = DeFiAddress.from('mainnet', p2pkhFixture.mainnet)
expect(p2pkh.valid).toBeTruthy()
- expect(p2pkh.type).toBe('P2PKH')
- expect(p2pkh.constructor.name).toBe('P2PKH')
- expect(p2pkh.network).toBe(MainNet)
+ expect(p2pkh.type).toStrictEqual('P2PKH')
+ expect(p2pkh.constructor.name).toStrictEqual('P2PKH')
+ expect(p2pkh.network).toStrictEqual(MainNet)
})
it('should work for all recognized network type', () => {
const testnet = DeFiAddress.from('testnet', p2pkhFixture.testnet)
expect(testnet.valid).toBeTruthy()
- expect(testnet.type).toBe('P2PKH')
- expect(testnet.constructor.name).toBe('P2PKH')
- expect(testnet.network).toBe(TestNet)
+ expect(testnet.type).toStrictEqual('P2PKH')
+ expect(testnet.constructor.name).toStrictEqual('P2PKH')
+ expect(testnet.network).toStrictEqual(TestNet)
const regtest = DeFiAddress.from('regtest', p2pkhFixture.regtest)
expect(regtest.valid).toBeTruthy()
- expect(regtest.type).toBe('P2PKH')
- expect(regtest.constructor.name).toBe('P2PKH')
- expect(regtest.network).toBe(RegTest)
+ expect(regtest.type).toStrictEqual('P2PKH')
+ expect(regtest.constructor.name).toStrictEqual('P2PKH')
+ expect(regtest.network).toStrictEqual(RegTest)
})
})
@@ -57,8 +57,8 @@ describe('P2PKH', () => {
// valid address, used on different network
const p2pkh = DeFiAddress.from('testnet', p2pkhFixture.mainnet)
expect(p2pkh.valid).toBeFalsy()
- // expect(p2pkh.type).toBe('P2PKH') // invalid address guessed type is not promising, as p2pkh and p2sh are versy similar
- expect(p2pkh.network).toBe(TestNet)
+ // expect(p2pkh.type).toStrictEqual('P2PKH') // invalid address guessed type is not promising, as p2pkh and p2sh are versy similar
+ expect(p2pkh.network).toStrictEqual(TestNet)
})
it('should get the type precisely', () => {
@@ -70,24 +70,24 @@ describe('P2PKH', () => {
describe('to()', () => {
it('should be able to build a new address using a public key hash (20 bytes, 40 char hex string)', () => {
const pubKeyHash = '134b0749882c225e8647df3a3417507c6f5b2797'
- expect(pubKeyHash.length).toEqual(40)
+ expect(pubKeyHash.length).toStrictEqual(40)
const p2pkh = P2PKH.to('regtest', pubKeyHash)
- expect(p2pkh.type).toEqual('P2PKH')
+ expect(p2pkh.type).toStrictEqual('P2PKH')
expect(p2pkh.valid).toBeTruthy()
const scriptStack = p2pkh.getScript()
- expect(scriptStack.stack.length).toEqual(5)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_DUP)
- expect(scriptStack.stack[1]).toEqual(OP_CODES.OP_HASH160)
- expect(scriptStack.stack[2]).toEqual(OP_CODES.OP_PUSHDATA_HEX_LE(pubKeyHash))
- expect(scriptStack.stack[3]).toEqual(OP_CODES.OP_EQUALVERIFY)
- expect(scriptStack.stack[4]).toEqual(OP_CODES.OP_CHECKSIG)
+ expect(scriptStack.stack.length).toStrictEqual(5)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_DUP)
+ expect(scriptStack.stack[1]).toStrictEqual(OP_CODES.OP_HASH160)
+ expect(scriptStack.stack[2]).toStrictEqual(OP_CODES.OP_PUSHDATA_HEX_LE(pubKeyHash))
+ expect(scriptStack.stack[3]).toStrictEqual(OP_CODES.OP_EQUALVERIFY)
+ expect(scriptStack.stack[4]).toStrictEqual(OP_CODES.OP_CHECKSIG)
})
it('should reject invalid data - not 20 bytes data', () => {
const pubKeyHash = '134b0749882c225e8647df3a3417507c6f5b27'
- expect(pubKeyHash.length).toEqual(38)
+ expect(pubKeyHash.length).toStrictEqual(38)
expect(() => {
P2PKH.to('regtest', pubKeyHash)
@@ -102,7 +102,7 @@ describe('P2PKH', () => {
try {
invalid.getScript()
} catch (e) {
- expect(e.message).toBe('InvalidDefiAddress')
+ expect(e.message).toStrictEqual('InvalidDefiAddress')
}
})
@@ -110,12 +110,12 @@ describe('P2PKH', () => {
const p2pkh = DeFiAddress.from('mainnet', p2pkhFixture.mainnet)
const scriptStack = p2pkh.getScript()
- expect(scriptStack.stack.length).toEqual(5)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_DUP)
- expect(scriptStack.stack[1]).toEqual(OP_CODES.OP_HASH160)
- expect(scriptStack.stack[2].type).toEqual('OP_PUSHDATA') // tested in `to()`
- expect(scriptStack.stack[3]).toEqual(OP_CODES.OP_EQUALVERIFY)
- expect(scriptStack.stack[4]).toEqual(OP_CODES.OP_CHECKSIG)
+ expect(scriptStack.stack.length).toStrictEqual(5)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_DUP)
+ expect(scriptStack.stack[1]).toStrictEqual(OP_CODES.OP_HASH160)
+ expect(scriptStack.stack[2].type).toStrictEqual('OP_PUSHDATA') // tested in `to()`
+ expect(scriptStack.stack[3]).toStrictEqual(OP_CODES.OP_EQUALVERIFY)
+ expect(scriptStack.stack[4]).toStrictEqual(OP_CODES.OP_CHECKSIG)
})
})
@@ -123,19 +123,19 @@ describe('P2PKH', () => {
const hex = bs58.decode(p2pkhFixture.mainnet).toString('hex').substring(2, 42) // take 20 bytes data only
const p2pkh = new P2PKH(MainNet, p2pkhFixture.mainnet, hex)
- expect(p2pkh.validatorPassed).toEqual(0)
+ expect(p2pkh.validatorPassed).toStrictEqual(0)
expect(p2pkh.valid).toBeFalsy()
const isValid = p2pkh.validate()
- expect(p2pkh.validatorPassed).toEqual(5)
+ expect(p2pkh.validatorPassed).toStrictEqual(5)
expect(isValid).toBeTruthy()
})
it('guess()', () => {
const p2pkh = DeFiAddress.guess(p2pkhFixture.mainnet)
expect(p2pkh.valid).toBeTruthy()
- expect(p2pkh.type).toBe('P2PKH')
- expect(p2pkh.constructor.name).toBe('P2PKH')
- expect(p2pkh.network).toBe(MainNet)
+ expect(p2pkh.type).toStrictEqual('P2PKH')
+ expect(p2pkh.constructor.name).toStrictEqual('P2PKH')
+ expect(p2pkh.network).toStrictEqual(MainNet)
})
})
diff --git a/packages/jellyfish-address/__tests__/p2sh.test.ts b/packages/jellyfish-address/__tests__/p2sh.test.ts
index 283de9f5b0..202dfd8426 100644
--- a/packages/jellyfish-address/__tests__/p2sh.test.ts
+++ b/packages/jellyfish-address/__tests__/p2sh.test.ts
@@ -27,23 +27,23 @@ describe('P2SH', () => {
it('should get the type precisely', () => {
const p2sh = DeFiAddress.from('mainnet', p2shFixture.mainnet)
expect(p2sh.valid).toBeTruthy()
- expect(p2sh.type).toBe('P2SH')
- expect(p2sh.constructor.name).toBe('P2SH')
- expect(p2sh.network).toBe(MainNet)
+ expect(p2sh.type).toStrictEqual('P2SH')
+ expect(p2sh.constructor.name).toStrictEqual('P2SH')
+ expect(p2sh.network).toStrictEqual(MainNet)
})
it('should work for all recognized network type', () => {
const testnet = DeFiAddress.from('testnet', p2shFixture.testnet)
expect(testnet.valid).toBeTruthy()
- expect(testnet.type).toBe('P2SH')
- expect(testnet.constructor.name).toBe('P2SH')
- expect(testnet.network).toBe(TestNet)
+ expect(testnet.type).toStrictEqual('P2SH')
+ expect(testnet.constructor.name).toStrictEqual('P2SH')
+ expect(testnet.network).toStrictEqual(TestNet)
const regtest = DeFiAddress.from('regtest', p2shFixture.regtest)
expect(regtest.valid).toBeTruthy()
- expect(regtest.type).toBe('P2SH')
- expect(regtest.constructor.name).toBe('P2SH')
- expect(regtest.network).toBe(RegTest)
+ expect(regtest.type).toStrictEqual('P2SH')
+ expect(regtest.constructor.name).toStrictEqual('P2SH')
+ expect(regtest.network).toStrictEqual(RegTest)
})
})
@@ -57,8 +57,8 @@ describe('P2SH', () => {
// valid address, used on different network
const p2sh = DeFiAddress.from('testnet', p2shFixture.mainnet)
expect(p2sh.valid).toBeFalsy()
- // expect(p2sh.type).toBe('P2SH') // invalid address guessed type is not promising, as p2sh and p2sh are versy similar
- expect(p2sh.network).toBe(TestNet)
+ // expect(p2sh.type).toStrictEqual('P2SH') // invalid address guessed type is not promising, as p2sh and p2sh are versy similar
+ expect(p2sh.network).toStrictEqual(TestNet)
})
it('should get the type precisely', () => {
@@ -70,28 +70,28 @@ describe('P2SH', () => {
describe('to()', () => {
it('should be able to build a new address using a public key hash (20 bytes, 40 char hex string)', () => {
const scriptHash = '134b0749882c225e8647df3a3417507c6f5b2797'
- expect(scriptHash.length).toEqual(40)
+ expect(scriptHash.length).toStrictEqual(40)
const p2sh = P2SH.to('regtest', scriptHash)
- expect(p2sh.type).toEqual('P2SH')
+ expect(p2sh.type).toStrictEqual('P2SH')
expect(p2sh.valid).toBeTruthy()
const scriptStack = p2sh.getScript()
- expect(scriptStack.stack.length).toEqual(3)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_HASH160)
- expect(scriptStack.stack[1]).toEqual(OP_CODES.OP_PUSHDATA_HEX_LE(scriptHash))
- expect(scriptStack.stack[2]).toEqual(OP_CODES.OP_EQUAL)
+ expect(scriptStack.stack.length).toStrictEqual(3)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_HASH160)
+ expect(scriptStack.stack[1]).toStrictEqual(OP_CODES.OP_PUSHDATA_HEX_LE(scriptHash))
+ expect(scriptStack.stack[2]).toStrictEqual(OP_CODES.OP_EQUAL)
})
it('should reject invalid data - not 20 bytes data', () => {
const scriptHash = '134b0749882c225e8647df3a3417507c6f5b27'
- expect(scriptHash.length).toEqual(38)
+ expect(scriptHash.length).toStrictEqual(38)
try {
P2SH.to('regtest', scriptHash)
throw new Error('should had failed')
} catch (e) {
- expect(e.message).toEqual('InvalidDataLength')
+ expect(e.message).toStrictEqual('InvalidDataLength')
}
})
})
@@ -103,7 +103,7 @@ describe('P2SH', () => {
try {
invalid.getScript()
} catch (e) {
- expect(e.message).toBe('InvalidDefiAddress')
+ expect(e.message).toStrictEqual('InvalidDefiAddress')
}
})
@@ -111,10 +111,10 @@ describe('P2SH', () => {
const p2sh = DeFiAddress.from('mainnet', p2shFixture.mainnet)
const scriptStack = p2sh.getScript()
- expect(scriptStack.stack.length).toEqual(3)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_HASH160)
- expect(scriptStack.stack[1].type).toEqual('OP_PUSHDATA')
- expect(scriptStack.stack[2]).toEqual(OP_CODES.OP_EQUAL)
+ expect(scriptStack.stack.length).toStrictEqual(3)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_HASH160)
+ expect(scriptStack.stack[1].type).toStrictEqual('OP_PUSHDATA')
+ expect(scriptStack.stack[2]).toStrictEqual(OP_CODES.OP_EQUAL)
})
})
@@ -122,19 +122,19 @@ describe('P2SH', () => {
const hex = bs58.decode(p2shFixture.mainnet).toString('hex').substring(2, 42) // take 20 bytes data only
const p2sh = new P2SH(MainNet, p2shFixture.mainnet, hex)
- expect(p2sh.validatorPassed).toEqual(0)
+ expect(p2sh.validatorPassed).toStrictEqual(0)
expect(p2sh.valid).toBeFalsy()
const isValid = p2sh.validate()
- expect(p2sh.validatorPassed).toEqual(5)
+ expect(p2sh.validatorPassed).toStrictEqual(5)
expect(isValid).toBeTruthy()
})
it('guess()', () => {
const p2sh = DeFiAddress.guess(p2shFixture.mainnet)
expect(p2sh.valid).toBeTruthy()
- expect(p2sh.type).toBe('P2SH')
- expect(p2sh.constructor.name).toBe('P2SH')
- expect(p2sh.network).toBe(MainNet)
+ expect(p2sh.type).toStrictEqual('P2SH')
+ expect(p2sh.constructor.name).toStrictEqual('P2SH')
+ expect(p2sh.network).toStrictEqual(MainNet)
})
})
diff --git a/packages/jellyfish-address/__tests__/p2wpkh.test.ts b/packages/jellyfish-address/__tests__/p2wpkh.test.ts
index c79d433269..fb71ccda3d 100644
--- a/packages/jellyfish-address/__tests__/p2wpkh.test.ts
+++ b/packages/jellyfish-address/__tests__/p2wpkh.test.ts
@@ -26,23 +26,23 @@ describe('P2WPKH', () => {
it('should get the type precisely', () => {
const p2wpkh = DeFiAddress.from('mainnet', p2wpkhFixture.mainnet)
expect(p2wpkh.valid).toBeTruthy()
- expect(p2wpkh.type).toBe('P2WPKH')
- expect(p2wpkh.constructor.name).toBe('P2WPKH')
- expect(p2wpkh.network).toBe(MainNet)
+ expect(p2wpkh.type).toStrictEqual('P2WPKH')
+ expect(p2wpkh.constructor.name).toStrictEqual('P2WPKH')
+ expect(p2wpkh.network).toStrictEqual(MainNet)
})
it('should work for all recognized network type', () => {
const testnet = DeFiAddress.from('testnet', p2wpkhFixture.testnet)
expect(testnet.valid).toBeTruthy()
- expect(testnet.type).toBe('P2WPKH')
- expect(testnet.constructor.name).toBe('P2WPKH')
- expect(testnet.network).toBe(TestNet)
+ expect(testnet.type).toStrictEqual('P2WPKH')
+ expect(testnet.constructor.name).toStrictEqual('P2WPKH')
+ expect(testnet.network).toStrictEqual(TestNet)
const regtest = DeFiAddress.from('regtest', p2wpkhFixture.regtest)
expect(regtest.valid).toBeTruthy()
- expect(regtest.type).toBe('P2WPKH')
- expect(regtest.constructor.name).toBe('P2WPKH')
- expect(regtest.network).toBe(RegTest)
+ expect(regtest.type).toStrictEqual('P2WPKH')
+ expect(regtest.constructor.name).toStrictEqual('P2WPKH')
+ expect(regtest.network).toStrictEqual(RegTest)
})
})
@@ -61,35 +61,35 @@ describe('P2WPKH', () => {
// valid address, used on different network
const p2wpkh = DeFiAddress.from('testnet', p2wpkhFixture.mainnet)
expect(p2wpkh.valid).toBeFalsy()
- // expect(p2wpkh.type).toBe('P2WPKH') // invalid address guessed type is not promising, as p2wpkh and p2wpkh are versy similar
- expect(p2wpkh.network).toBe(TestNet)
+ // expect(p2wpkh.type).toStrictEqual('P2WPKH') // invalid address guessed type is not promising, as p2wpkh and p2wpkh are versy similar
+ expect(p2wpkh.network).toStrictEqual(TestNet)
})
})
describe('to()', () => {
it('should be able to build a new address using a public key hash (20 bytes, 40 char hex string)', () => {
const data = '0e7c0ab18b305bc987a266dc06de26fcfab4b56a' // 20 bytes
- expect(data.length).toEqual(40)
+ expect(data.length).toStrictEqual(40)
const p2wpkh = P2WPKH.to('regtest', data)
- expect(p2wpkh.type).toEqual('P2WPKH')
+ expect(p2wpkh.type).toStrictEqual('P2WPKH')
expect(p2wpkh.valid).toBeTruthy()
const scriptStack = p2wpkh.getScript()
- expect(scriptStack.stack.length).toEqual(2)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_0)
- expect(scriptStack.stack[1]).toEqual(OP_CODES.OP_PUSHDATA_HEX_LE(data))
+ expect(scriptStack.stack.length).toStrictEqual(2)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_0)
+ expect(scriptStack.stack[1]).toStrictEqual(OP_CODES.OP_PUSHDATA_HEX_LE(data))
})
it('should reject invalid data - not 32 bytes data', () => {
const pubKeyHash = '9e1be07558ea5cc8e02ed1d80c0911048afad949affa36d5c3951e3159dbea19'
- expect(pubKeyHash.length).toEqual(64) // testing with a p2wpkh data
+ expect(pubKeyHash.length).toStrictEqual(64) // testing with a p2wpkh data
try {
P2WPKH.to('regtest', pubKeyHash)
throw new Error('should had failed')
} catch (e) {
- expect(e.message).toEqual('InvalidPubKeyHashLength')
+ expect(e.message).toStrictEqual('InvalidPubKeyHashLength')
}
})
})
@@ -101,7 +101,7 @@ describe('P2WPKH', () => {
try {
invalid.getScript()
} catch (e) {
- expect(e.message).toBe('InvalidDefiAddress')
+ expect(e.message).toStrictEqual('InvalidDefiAddress')
}
})
@@ -109,9 +109,9 @@ describe('P2WPKH', () => {
const p2wpkh = DeFiAddress.from('mainnet', p2wpkhFixture.mainnet)
const scriptStack = p2wpkh.getScript()
- expect(scriptStack.stack.length).toEqual(2)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_0)
- expect(scriptStack.stack[1].type).toEqual('OP_PUSHDATA')
+ expect(scriptStack.stack.length).toStrictEqual(2)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_0)
+ expect(scriptStack.stack[1].type).toStrictEqual('OP_PUSHDATA')
})
})
@@ -119,19 +119,19 @@ describe('P2WPKH', () => {
const data = '0e7c0ab18b305bc987a266dc06de26fcfab4b56a' // 20 bytes
const p2wpkh = new P2WPKH(RegTest, p2wpkhFixture.regtest, data)
- expect(p2wpkh.validatorPassed).toEqual(0)
+ expect(p2wpkh.validatorPassed).toStrictEqual(0)
expect(p2wpkh.valid).toBeFalsy()
const isValid = p2wpkh.validate()
- expect(p2wpkh.validatorPassed).toEqual(5) // length, network prefix, data character set
+ expect(p2wpkh.validatorPassed).toStrictEqual(5) // length, network prefix, data character set
expect(isValid).toBeTruthy()
})
it('guess()', () => {
const p2wpkh = DeFiAddress.guess(p2wpkhFixture.mainnet)
expect(p2wpkh.valid).toBeTruthy()
- expect(p2wpkh.type).toBe('P2WPKH')
- expect(p2wpkh.constructor.name).toBe('P2WPKH')
- expect(p2wpkh.network).toBe(MainNet)
+ expect(p2wpkh.type).toStrictEqual('P2WPKH')
+ expect(p2wpkh.constructor.name).toStrictEqual('P2WPKH')
+ expect(p2wpkh.network).toStrictEqual(MainNet)
})
})
diff --git a/packages/jellyfish-address/__tests__/p2wsh.test.ts b/packages/jellyfish-address/__tests__/p2wsh.test.ts
index 576c0fe69e..9520b7b47f 100644
--- a/packages/jellyfish-address/__tests__/p2wsh.test.ts
+++ b/packages/jellyfish-address/__tests__/p2wsh.test.ts
@@ -16,23 +16,23 @@ describe('P2WSH', () => {
it('should get the type precisely', () => {
const p2sh = DeFiAddress.from('mainnet', p2wshFixture.mainnet)
expect(p2sh.valid).toBeTruthy()
- expect(p2sh.type).toBe('P2WSH')
- expect(p2sh.constructor.name).toBe('P2WSH')
- expect(p2sh.network).toBe(MainNet)
+ expect(p2sh.type).toStrictEqual('P2WSH')
+ expect(p2sh.constructor.name).toStrictEqual('P2WSH')
+ expect(p2sh.network).toStrictEqual(MainNet)
})
it('should work for all recognized network type', () => {
const testnet = DeFiAddress.from('testnet', p2wshFixture.testnet)
expect(testnet.valid).toBeTruthy()
- expect(testnet.type).toBe('P2WSH')
- expect(testnet.constructor.name).toBe('P2WSH')
- expect(testnet.network).toBe(TestNet)
+ expect(testnet.type).toStrictEqual('P2WSH')
+ expect(testnet.constructor.name).toStrictEqual('P2WSH')
+ expect(testnet.network).toStrictEqual(TestNet)
const regtest = DeFiAddress.from('regtest', p2wshFixture.regtest)
expect(regtest.valid).toBeTruthy()
- expect(regtest.type).toBe('P2WSH')
- expect(regtest.constructor.name).toBe('P2WSH')
- expect(regtest.network).toBe(RegTest)
+ expect(regtest.type).toStrictEqual('P2WSH')
+ expect(regtest.constructor.name).toStrictEqual('P2WSH')
+ expect(regtest.network).toStrictEqual(RegTest)
})
})
@@ -51,35 +51,35 @@ describe('P2WSH', () => {
// valid address, used on different network
const p2sh = DeFiAddress.from('testnet', p2wshFixture.mainnet)
expect(p2sh.valid).toBeFalsy()
- // expect(p2sh.type).toBe('P2WSH') // invalid address guessed type is not promising, as p2wsh and p2sh are versy similar
- expect(p2sh.network).toBe(TestNet)
+ // expect(p2sh.type).toStrictEqual('P2WSH') // invalid address guessed type is not promising, as p2wsh and p2sh are versy similar
+ expect(p2sh.network).toStrictEqual(TestNet)
})
})
describe('to()', () => {
it('should be able to build a new address using a script hash (32 bytes, 64 char hex string)', () => {
const data = '9e1be07558ea5cc8e02ed1d80c0911048afad949affa36d5c3951e3159dbea19' // 32 bytes
- expect(data.length).toEqual(64)
+ expect(data.length).toStrictEqual(64)
const p2wsh = P2WSH.to('regtest', data)
- expect(p2wsh.type).toEqual('P2WSH')
+ expect(p2wsh.type).toStrictEqual('P2WSH')
expect(p2wsh.valid).toBeTruthy()
const scriptStack = p2wsh.getScript()
- expect(scriptStack.stack.length).toEqual(2)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_0)
- expect(scriptStack.stack[1]).toEqual(OP_CODES.OP_PUSHDATA_HEX_LE(data))
+ expect(scriptStack.stack.length).toStrictEqual(2)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_0)
+ expect(scriptStack.stack[1]).toStrictEqual(OP_CODES.OP_PUSHDATA_HEX_LE(data))
})
it('should reject invalid data - not 32 bytes data', () => {
const pubKeyHash = '134b0749882c225e8647df3a3417507c6f5b27'
- expect(pubKeyHash.length).toEqual(38)
+ expect(pubKeyHash.length).toStrictEqual(38)
try {
P2WSH.to('regtest', pubKeyHash)
throw new Error('should had failed')
} catch (e) {
- expect(e.message).toEqual('InvalidScriptHashLength')
+ expect(e.message).toStrictEqual('InvalidScriptHashLength')
}
})
})
@@ -91,7 +91,7 @@ describe('P2WSH', () => {
try {
invalid.getScript()
} catch (e) {
- expect(e.message).toBe('InvalidDefiAddress')
+ expect(e.message).toStrictEqual('InvalidDefiAddress')
}
})
@@ -99,9 +99,9 @@ describe('P2WSH', () => {
const p2wsh = DeFiAddress.from('mainnet', p2wshFixture.mainnet)
const scriptStack = p2wsh.getScript()
- expect(scriptStack.stack.length).toEqual(2)
- expect(scriptStack.stack[0]).toEqual(OP_CODES.OP_0)
- expect(scriptStack.stack[1].type).toEqual('OP_PUSHDATA')
+ expect(scriptStack.stack.length).toStrictEqual(2)
+ expect(scriptStack.stack[0]).toStrictEqual(OP_CODES.OP_0)
+ expect(scriptStack.stack[1].type).toStrictEqual('OP_PUSHDATA')
})
})
@@ -109,19 +109,19 @@ describe('P2WSH', () => {
const data = '9e1be07558ea5cc8e02ed1d80c0911048afad949affa36d5c3951e3159dbea19' // 32 bytes
const p2wsh = new P2WSH(RegTest, p2wshFixture.regtest, data)
- expect(p2wsh.validatorPassed).toEqual(0)
+ expect(p2wsh.validatorPassed).toStrictEqual(0)
expect(p2wsh.valid).toBeFalsy()
const isValid = p2wsh.validate()
- // expect(p2wsh.validatorPassed).toEqual(4) // length, network prefix, data character set
+ // expect(p2wsh.validatorPassed).toStrictEqual(4) // length, network prefix, data character set
expect(isValid).toBeTruthy()
})
it('guess()', () => {
const p2wsh = DeFiAddress.guess(p2wshFixture.mainnet)
expect(p2wsh.valid).toBeTruthy()
- expect(p2wsh.type).toBe('P2WSH')
- expect(p2wsh.constructor.name).toBe('P2WSH')
- expect(p2wsh.network).toBe(MainNet)
+ expect(p2wsh.type).toStrictEqual('P2WSH')
+ expect(p2wsh.constructor.name).toStrictEqual('P2WSH')
+ expect(p2wsh.network).toStrictEqual(MainNet)
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/account.test.ts b/packages/jellyfish-api-core/__tests__/category/account.test.ts
index 6014deefc3..700642a189 100644
--- a/packages/jellyfish-api-core/__tests__/category/account.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/account.test.ts
@@ -76,13 +76,13 @@ describe('masternode', () => {
for (let i = 0; i < accounts.length; i += 1) {
const account = accounts[i]
- expect(typeof account.key).toBe('string')
- expect(typeof account.owner === 'object').toBe(true)
- expect(typeof account.owner.asm).toBe('string')
- expect(account.owner.reqSigs instanceof BigNumber).toBe(true)
- expect(typeof account.owner.type).toBe('string')
+ expect(typeof account.key).toStrictEqual('string')
+ expect(typeof account.owner === 'object').toStrictEqual(true)
+ expect(typeof account.owner.asm).toStrictEqual('string')
+ expect(account.owner.reqSigs instanceof BigNumber).toStrictEqual(true)
+ expect(typeof account.owner.type).toStrictEqual('string')
expect(account.owner.addresses.length).toBeGreaterThan(0)
- expect(typeof account.amount).toBe('string') // 10.00000000@DFI
+ expect(typeof account.amount).toStrictEqual('string') // 10.00000000@DFI
}
})
@@ -95,7 +95,7 @@ describe('masternode', () => {
}
const lastAccounts = await client.account.listAccounts(pagination)
- expect(lastAccounts.length).toBe(1)
+ expect(lastAccounts.length).toStrictEqual(1)
})
it('should listAccounts with pagination.limit', async () => {
@@ -104,7 +104,7 @@ describe('masternode', () => {
limit: 2
}
const accounts = await client.account.listAccounts(pagination)
- expect(accounts.length).toBe(2)
+ expect(accounts.length).toStrictEqual(2)
})
})
@@ -115,9 +115,9 @@ describe('masternode', () => {
for (let i = 0; i < accounts.length; i += 1) {
const account = accounts[i]
- expect(typeof account.key).toBe('string')
- expect(typeof account.owner).toBe('string')
- expect(typeof account.amount).toBe('string') // 10.00000000@DFI
+ expect(typeof account.key).toStrictEqual('string')
+ expect(typeof account.owner).toStrictEqual('string')
+ expect(typeof account.amount).toStrictEqual('string') // 10.00000000@DFI
}
})
@@ -128,12 +128,12 @@ describe('masternode', () => {
for (let i = 0; i < accounts.length; i += 1) {
const account = accounts[i]
- expect(typeof account.key).toBe('string')
- expect(typeof account.owner).toBe('string')
+ expect(typeof account.key).toStrictEqual('string')
+ expect(typeof account.owner).toStrictEqual('string')
- expect(typeof account.amount === 'object').toBe(true)
+ expect(typeof account.amount === 'object').toStrictEqual(true)
for (const k in account.amount) {
- expect(account.amount[k] instanceof BigNumber).toBe(true) // [{'0': 100}]
+ expect(account.amount[k] instanceof BigNumber).toStrictEqual(true) // [{'0': 100}]
}
}
})
@@ -145,16 +145,16 @@ describe('masternode', () => {
for (let i = 0; i < accounts.length; i += 1) {
const account = accounts[i]
- expect(typeof account.key).toBe('string')
- expect(typeof account.owner === 'object').toBe(true)
- expect(typeof account.owner.asm).toBe('string')
- expect(account.owner.reqSigs instanceof BigNumber).toBe(true)
- expect(typeof account.owner.type).toBe('string')
+ expect(typeof account.key).toStrictEqual('string')
+ expect(typeof account.owner === 'object').toStrictEqual(true)
+ expect(typeof account.owner.asm).toStrictEqual('string')
+ expect(account.owner.reqSigs instanceof BigNumber).toStrictEqual(true)
+ expect(typeof account.owner.type).toStrictEqual('string')
expect(account.owner.addresses.length).toBeGreaterThan(0)
- expect(typeof account.amount === 'object').toBe(true)
+ expect(typeof account.amount === 'object').toStrictEqual(true)
for (const k in account.amount) {
- expect(account.amount[k] instanceof BigNumber).toBe(true) // [{'0': 100}]
+ expect(account.amount[k] instanceof BigNumber).toStrictEqual(true) // [{'0': 100}]
}
}
})
@@ -166,13 +166,13 @@ describe('masternode', () => {
for (let i = 0; i < accounts.length; i += 1) {
const account = accounts[i]
- expect(typeof account.key).toBe('string')
- expect(typeof account.owner === 'object').toBe(true)
- expect(typeof account.owner.asm).toBe('string')
- expect(account.owner.reqSigs instanceof BigNumber).toBe(true)
- expect(typeof account.owner.type).toBe('string')
+ expect(typeof account.key).toStrictEqual('string')
+ expect(typeof account.owner === 'object').toStrictEqual(true)
+ expect(typeof account.owner.asm).toStrictEqual('string')
+ expect(account.owner.reqSigs instanceof BigNumber).toStrictEqual(true)
+ expect(typeof account.owner.type).toStrictEqual('string')
expect(account.owner.addresses.length).toBeGreaterThan(0)
- expect(typeof account.amount).toBe('string') // 10.00000000@DFI
+ expect(typeof account.amount).toStrictEqual('string') // 10.00000000@DFI
}
})
@@ -183,13 +183,13 @@ describe('masternode', () => {
for (let i = 0; i < accounts.length; i += 1) {
const account = accounts[i]
- expect(typeof account.key).toBe('string')
- expect(typeof account.owner === 'object').toBe(true)
- expect(typeof account.owner.asm).toBe('string')
- expect(account.owner.reqSigs instanceof BigNumber).toBe(true)
- expect(typeof account.owner.type).toBe('string')
+ expect(typeof account.key).toStrictEqual('string')
+ expect(typeof account.owner === 'object').toStrictEqual(true)
+ expect(typeof account.owner.asm).toStrictEqual('string')
+ expect(account.owner.reqSigs instanceof BigNumber).toStrictEqual(true)
+ expect(typeof account.owner.type).toStrictEqual('string')
expect(account.owner.addresses.length).toBeGreaterThan(0)
- expect(typeof account.amount).toBe('string') // 10.00000000@DFI
+ expect(typeof account.amount).toStrictEqual('string') // 10.00000000@DFI
}
})
})
@@ -202,7 +202,7 @@ describe('masternode', () => {
const account = await client.account.getAccount(accounts[0].owner.addresses[0])
expect(account.length).toBeGreaterThan(0)
for (let i = 0; i < account.length; i += 1) {
- expect(typeof account[i]).toBe('string')
+ expect(typeof account[i]).toStrictEqual('string')
}
})
@@ -225,10 +225,10 @@ describe('masternode', () => {
// [ '187.00000000@DBTC', '154.00000000@DETH' ]
const account = await client.account.getAccount(accounts[0].owner.addresses[0], pagination)
- expect(account.length).toBe(1)
+ expect(account.length).toStrictEqual(1)
for (let i = 0; i < account.length; i += 1) {
- expect(typeof account[i]).toBe('string')
+ expect(typeof account[i]).toStrictEqual('string')
}
})
@@ -239,16 +239,16 @@ describe('masternode', () => {
limit: 1
}
const account = await client.account.getAccount(accounts[0].owner.addresses[0], pagination)
- expect(account.length).toBe(1)
+ expect(account.length).toStrictEqual(1)
})
it('should getAccount with indexedAmount true', async () => {
const accounts = await waitForListingAccounts()
const account = await client.account.getAccount(accounts[0].owner.addresses[0], {}, { indexedAmounts: true })
- expect(typeof account).toBe('object')
+ expect(typeof account).toStrictEqual('object')
for (const k in account) {
- expect(typeof account[k]).toBe('number')
+ expect(typeof account[k]).toStrictEqual('number')
}
})
})
@@ -262,7 +262,7 @@ describe('masternode', () => {
const tokenBalances = await client.account.getTokenBalances()
for (let i = 0; i < tokenBalances.length; i += 1) {
- expect(typeof tokenBalances[i]).toBe('string') // [ '300.00000000@0', '200.00000000@1' ]
+ expect(typeof tokenBalances[i]).toStrictEqual('string') // [ '300.00000000@0', '200.00000000@1' ]
}
})
@@ -281,27 +281,27 @@ describe('masternode', () => {
including_start: true
}
const tokenBalances = await client.account.getTokenBalances(pagination)
- expect(tokenBalances.length).toBe(1)
+ expect(tokenBalances.length).toStrictEqual(1)
})
it('should getTokenBalances with pagination limit', async () => {
await waitForExpect(async () => {
const tokenBalances = await client.account.getTokenBalances()
- expect(tokenBalances.length).toBe(2)
+ expect(tokenBalances.length).toStrictEqual(2)
})
const pagination = {
limit: 1
}
const tokenBalances = await client.account.getTokenBalances(pagination)
- expect(tokenBalances.length).toBe(1)
+ expect(tokenBalances.length).toStrictEqual(1)
})
it('should getTokenBalances with indexedAmounts true', async () => {
await waitForExpect(async () => {
const tokenBalances = await client.account.getTokenBalances({}, true, { symbolLookup: false })
- expect(typeof tokenBalances === 'object').toBe(true)
+ expect(typeof tokenBalances === 'object').toStrictEqual(true)
for (const k in tokenBalances) {
- expect(tokenBalances[k] instanceof BigNumber).toBe(true)
+ expect(tokenBalances[k] instanceof BigNumber).toStrictEqual(true)
}
})
})
@@ -314,7 +314,7 @@ describe('masternode', () => {
const tokenBalances = await client.account.getTokenBalances({}, false, { symbolLookup: true })
for (let i = 0; i < tokenBalances.length; i += 1) {
- expect(typeof tokenBalances[i]).toBe('string') // [ '300.00000000@DFI', '200.00000000@DBTC' ]
+ expect(typeof tokenBalances[i]).toStrictEqual('string') // [ '300.00000000@DFI', '200.00000000@DBTC' ]
}
})
})
@@ -330,15 +330,15 @@ describe('masternode', () => {
for (let i = 0; i < accountHistories.length; i += 1) {
const accountHistory = accountHistories[i]
- expect(typeof accountHistory.owner).toBe('string')
- expect(typeof accountHistory.blockHeight).toBe('number')
- expect(typeof accountHistory.blockHash).toBe('string')
- expect(typeof accountHistory.blockTime).toBe('number')
- expect(typeof accountHistory.type).toBe('string')
- expect(typeof accountHistory.txn).toBe('number')
- expect(typeof accountHistory.txid).toBe('string')
+ expect(typeof accountHistory.owner).toStrictEqual('string')
+ expect(typeof accountHistory.blockHeight).toStrictEqual('number')
+ expect(typeof accountHistory.blockHash).toStrictEqual('string')
+ expect(typeof accountHistory.blockTime).toStrictEqual('number')
+ expect(typeof accountHistory.type).toStrictEqual('string')
+ expect(typeof accountHistory.txn).toStrictEqual('number')
+ expect(typeof accountHistory.txid).toStrictEqual('string')
expect(accountHistory.amounts.length).toBeGreaterThan(0)
- expect(typeof accountHistory.amounts[0]).toBe('string') // [ '10.00000000@DFI' ]
+ expect(typeof accountHistory.amounts[0]).toStrictEqual('string') // [ '10.00000000@DFI' ]
}
})
@@ -352,15 +352,15 @@ describe('masternode', () => {
for (let i = 0; i < accountHistories.length; i += 1) {
const accountHistory = accountHistories[i]
- expect(typeof accountHistory.owner).toBe('string')
- expect(typeof accountHistory.blockHeight).toBe('number')
- expect(typeof accountHistory.blockHash).toBe('string')
- expect(typeof accountHistory.blockTime).toBe('number')
- expect(typeof accountHistory.type).toBe('string')
- expect(typeof accountHistory.txn).toBe('number')
- expect(typeof accountHistory.txid).toBe('string')
+ expect(typeof accountHistory.owner).toStrictEqual('string')
+ expect(typeof accountHistory.blockHeight).toStrictEqual('number')
+ expect(typeof accountHistory.blockHash).toStrictEqual('string')
+ expect(typeof accountHistory.blockTime).toStrictEqual('number')
+ expect(typeof accountHistory.type).toStrictEqual('string')
+ expect(typeof accountHistory.txn).toStrictEqual('number')
+ expect(typeof accountHistory.txid).toStrictEqual('string')
expect(accountHistory.amounts.length).toBeGreaterThan(0)
- expect(typeof accountHistory.amounts[0]).toBe('string')
+ expect(typeof accountHistory.amounts[0]).toStrictEqual('string')
}
})
@@ -374,7 +374,7 @@ describe('masternode', () => {
for (let i = 0; i < accountHistories.length; i += 1) {
const accountHistory = accountHistories[i]
- expect(addresses.includes(accountHistory.owner)).toBe(true)
+ expect(addresses.includes(accountHistory.owner)).toStrictEqual(true)
}
})
@@ -390,7 +390,7 @@ describe('masternode', () => {
const accountHistories = await client.account.listAccountHistory(address)
for (let i = 0; i < accountHistories.length; i += 1) {
const accountHistory = accountHistories[i]
- expect(accountHistory.owner).toBe(address)
+ expect(accountHistory.owner).toStrictEqual(address)
}
})
@@ -434,7 +434,7 @@ describe('masternode', () => {
const accountHistories = await client.account.listAccountHistory('mine', options)
for (let i = 0; i < accountHistories.length; i += 1) {
const accountHistory = accountHistories[i]
- expect(accountHistory.txn).not.toBe('blockReward')
+ expect(accountHistory.txn).not.toStrictEqual('blockReward')
}
})
@@ -454,7 +454,7 @@ describe('masternode', () => {
for (let j = 0; j < accountHistory.amounts.length; j += 1) {
const amount = accountHistory.amounts[j]
const symbol = amount.split('@')[1]
- expect(symbol).toBe('DBTC')
+ expect(symbol).toStrictEqual('DBTC')
}
}
})
@@ -468,7 +468,7 @@ describe('masternode', () => {
const accountHistories = await client.account.listAccountHistory('mine', { txtype: 'M' })
for (let i = 0; i < accountHistories.length; i += 1) {
const accountHistory = accountHistories[i]
- expect(accountHistory.type).toBe('MintToken')
+ expect(accountHistory.type).toStrictEqual('MintToken')
}
})
@@ -478,7 +478,7 @@ describe('masternode', () => {
limit: 1
}
const accountHistories = await client.account.listAccountHistory('mine', options)
- expect(accountHistories.length).toBe(1)
+ expect(accountHistories.length).toStrictEqual(1)
})
})
})
@@ -492,8 +492,8 @@ describe('masternode', () => {
const data = await client.account.utxosToAccount(payload)
- expect(typeof data).toBe('string')
- expect(data.length).toBe(64)
+ expect(typeof data).toStrictEqual('string')
+ expect(data.length).toStrictEqual(64)
})
it('should utxosToAccount with utxos', async () => {
@@ -512,8 +512,8 @@ describe('masternode', () => {
const data = await client.account.utxosToAccount(payload, inputs)
- expect(typeof data).toBe('string')
- expect(data.length).toBe(64)
+ expect(typeof data).toStrictEqual('string')
+ expect(data.length).toStrictEqual(64)
})
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/blockchain.test.ts b/packages/jellyfish-api-core/__tests__/category/blockchain.test.ts
index 17239616b8..0e4c3d7bb2 100644
--- a/packages/jellyfish-api-core/__tests__/category/blockchain.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/blockchain.test.ts
@@ -19,27 +19,27 @@ describe('non masternode', () => {
it('should getBlockchainInfo', async () => {
const info = await client.blockchain.getBlockchainInfo()
- expect(info.chain).toBe('regtest')
- expect(info.blocks).toBe(0)
- expect(info.headers).toBe(0)
+ expect(info.chain).toStrictEqual('regtest')
+ expect(info.blocks).toStrictEqual(0)
+ expect(info.headers).toStrictEqual(0)
- expect(info.bestblockhash.length).toBe(64)
+ expect(info.bestblockhash.length).toStrictEqual(64)
expect(info.difficulty).toBeGreaterThan(0)
expect(info.mediantime).toBeGreaterThan(1550000000)
- expect(info.verificationprogress).toBe(1)
- expect(info.initialblockdownload).toBe(true)
- expect(info.chainwork.length).toBe(64)
+ expect(info.verificationprogress).toStrictEqual(1)
+ expect(info.initialblockdownload).toStrictEqual(true)
+ expect(info.chainwork.length).toStrictEqual(64)
expect(info.size_on_disk).toBeGreaterThan(0)
- expect(info.pruned).toBe(false)
+ expect(info.pruned).toStrictEqual(false)
- expect(info.softforks.amk.type).toBe('buried')
- expect(info.softforks.amk.active).toBe(true)
- expect(info.softforks.amk.height).toBe(0)
+ expect(info.softforks.amk.type).toStrictEqual('buried')
+ expect(info.softforks.amk.active).toStrictEqual(true)
+ expect(info.softforks.amk.height).toStrictEqual(0)
- expect(info.softforks.segwit.type).toBe('buried')
- expect(info.softforks.segwit.active).toBe(true)
- expect(info.softforks.segwit.height).toBe(0)
+ expect(info.softforks.segwit.type).toStrictEqual('buried')
+ expect(info.softforks.segwit.active).toStrictEqual(true)
+ expect(info.softforks.segwit.height).toStrictEqual(0)
})
})
@@ -78,19 +78,19 @@ describe('masternode', () => {
const info = await client.blockchain.getBlockchainInfo()
- expect(info.chain).toBe('regtest')
+ expect(info.chain).toStrictEqual('regtest')
expect(info.blocks).toBeGreaterThan(0)
expect(info.headers).toBeGreaterThan(0)
- expect(info.bestblockhash.length).toBe(64)
+ expect(info.bestblockhash.length).toStrictEqual(64)
expect(info.difficulty).toBeGreaterThan(0)
expect(info.mediantime).toBeGreaterThan(1550000000)
- expect(info.verificationprogress).toBe(1)
- expect(info.initialblockdownload).toBe(false)
- expect(info.chainwork.length).toBe(64)
+ expect(info.verificationprogress).toStrictEqual(1)
+ expect(info.initialblockdownload).toStrictEqual(false)
+ expect(info.chainwork.length).toStrictEqual(64)
expect(info.size_on_disk).toBeGreaterThan(0)
- expect(info.pruned).toBe(false)
+ expect(info.pruned).toStrictEqual(false)
})
})
@@ -98,14 +98,14 @@ describe('masternode', () => {
it('should getBlock with verbosity 0 and return just a string that is serialized, hex-encoded data for block', async () => {
const blockHash = await waitForBlockHash(1)
const hash: string = await client.blockchain.getBlock(blockHash, 0)
- expect(typeof hash).toBe('string')
+ expect(typeof hash).toStrictEqual('string')
})
it('should getBlock with verbosity 1 and return block with tx as hex', async () => {
const blockHash = await waitForBlockHash(1)
const block: blockchain.Block = await client.blockchain.getBlock(blockHash, 1)
- expect(block.hash.length).toBe(64)
+ expect(block.hash.length).toStrictEqual(64)
expect(block.confirmations).toBeGreaterThanOrEqual(2)
expect(block.strippedsize).toBeGreaterThanOrEqual(360)
@@ -114,17 +114,17 @@ describe('masternode', () => {
expect(block.weight).toBeGreaterThanOrEqual(1476)
expect(block.height).toBeGreaterThanOrEqual(1)
- expect(block.masternode.length).toBe(64)
- expect(block.minter.length).toBe(34) // legacy address length
+ expect(block.masternode.length).toStrictEqual(64)
+ expect(block.minter.length).toStrictEqual(34) // legacy address length
expect(block.mintedBlocks).toBeGreaterThanOrEqual(1)
- expect(block.stakeModifier.length).toBe(64)
+ expect(block.stakeModifier.length).toStrictEqual(64)
expect(block.version).toBeGreaterThanOrEqual(536870912)
expect(block.versionHex).toStrictEqual('20000000')
- expect(block.merkleroot.length).toBe(64)
+ expect(block.merkleroot.length).toStrictEqual(64)
expect(block.tx.length).toBeGreaterThanOrEqual(1)
- expect(block.tx[0].length).toBe(64)
+ expect(block.tx[0].length).toStrictEqual(64)
expect(block.time).toBeGreaterThan(1)
expect(block.mediantime).toBeGreaterThan(1)
@@ -132,9 +132,9 @@ describe('masternode', () => {
expect(block.bits).toStrictEqual('207fffff')
expect(block.difficulty).toBeGreaterThan(0)
- expect(block.chainwork.length).toBe(64)
+ expect(block.chainwork.length).toStrictEqual(64)
expect(block.nTx).toBeGreaterThanOrEqual(1)
- expect(block.previousblockhash.length).toBe(64)
+ expect(block.previousblockhash.length).toStrictEqual(64)
})
it('should getBlock with verbosity 2 and return block with tx as RawText', async () => {
@@ -145,17 +145,17 @@ describe('masternode', () => {
expect(block.tx[0].vin[0].coinbase).toStrictEqual('5100')
expect(block.tx[0].vin[0].sequence).toBeGreaterThanOrEqual(4294967295)
- expect(block.tx[0].vout[0].n).toBe(0)
- expect(block.tx[0].vout[0].value.toString(10)).toBe('38')
+ expect(block.tx[0].vout[0].n).toStrictEqual(0)
+ expect(block.tx[0].vout[0].value.toString(10)).toStrictEqual('38')
expect(block.tx[0].vout[0].value instanceof BigNumber).toBeTruthy()
- expect(block.tx[0].vout[0].scriptPubKey.asm).toBe('OP_DUP OP_HASH160 b36814fd26190b321aa985809293a41273cfe15e OP_EQUALVERIFY OP_CHECKSIG')
- expect(block.tx[0].vout[0].scriptPubKey.hex).toBe('76a914b36814fd26190b321aa985809293a41273cfe15e88ac')
+ expect(block.tx[0].vout[0].scriptPubKey.asm).toStrictEqual('OP_DUP OP_HASH160 b36814fd26190b321aa985809293a41273cfe15e OP_EQUALVERIFY OP_CHECKSIG')
+ expect(block.tx[0].vout[0].scriptPubKey.hex).toStrictEqual('76a914b36814fd26190b321aa985809293a41273cfe15e88ac')
expect(block.tx[0].vout[0].scriptPubKey.reqSigs).toBeGreaterThanOrEqual(1)
- expect(block.tx[0].vout[0].scriptPubKey.type).toBe('pubkeyhash')
- expect(block.tx[0].vout[0].scriptPubKey.addresses[0].length).toBe(34)
+ expect(block.tx[0].vout[0].scriptPubKey.type).toStrictEqual('pubkeyhash')
+ expect(block.tx[0].vout[0].scriptPubKey.addresses[0].length).toStrictEqual(34)
- expect(block.tx[0].vout[0].tokenId).toBe(0)
+ expect(block.tx[0].vout[0].tokenId).toStrictEqual(0)
})
})
@@ -164,14 +164,14 @@ describe('masternode', () => {
const blockHash = await waitForBlockHash(1)
const blockHeader: blockchain.BlockHeader = await client.blockchain.getBlockHeader(blockHash, true)
- expect(blockHeader.hash.length).toBe(64)
+ expect(blockHeader.hash.length).toStrictEqual(64)
expect(blockHeader.confirmations).toBeGreaterThanOrEqual(2)
expect(blockHeader.height).toBeGreaterThanOrEqual(1)
expect(blockHeader.version).toBeGreaterThanOrEqual(536870912)
expect(blockHeader.versionHex).toStrictEqual('20000000')
- expect(blockHeader.merkleroot.length).toBe(64)
+ expect(blockHeader.merkleroot.length).toStrictEqual(64)
expect(blockHeader.time).toBeGreaterThan(1)
expect(blockHeader.mediantime).toBeGreaterThan(1)
@@ -179,16 +179,16 @@ describe('masternode', () => {
expect(blockHeader.bits).toStrictEqual('207fffff')
expect(blockHeader.difficulty).toBeGreaterThan(0)
- expect(blockHeader.chainwork.length).toBe(64)
+ expect(blockHeader.chainwork.length).toStrictEqual(64)
expect(blockHeader.nTx).toBeGreaterThanOrEqual(1)
- expect(blockHeader.previousblockhash.length).toBe(64)
- expect(blockHeader.nextblockhash.length).toBe(64)
+ expect(blockHeader.previousblockhash.length).toStrictEqual(64)
+ expect(blockHeader.nextblockhash.length).toStrictEqual(64)
})
it('should getBlockHeader with verbosity false and return a string that is serialized, hex-encoded data for block header', async () => {
const blockHash = await waitForBlockHash(1)
const hash: string = await client.blockchain.getBlockHeader(blockHash, false)
- expect(typeof hash).toBe('string')
+ expect(typeof hash).toStrictEqual('string')
})
})
@@ -200,8 +200,8 @@ describe('masternode', () => {
})
const blockHash: string = await client.blockchain.getBlockHash(1)
- expect(typeof blockHash).toBe('string')
- expect(blockHash.length).toBe(64)
+ expect(typeof blockHash).toStrictEqual('string')
+ expect(blockHash.length).toStrictEqual(64)
})
})
@@ -223,15 +223,15 @@ describe('masternode', () => {
const txOut = await client.blockchain.getTxOut(txId, 0)
expect(txOut).toHaveProperty('bestblock')
expect(txOut.confirmations).toBeGreaterThanOrEqual(1)
- expect(txOut.value instanceof BigNumber).toBe(true)
- expect(txOut.value.toString()).toBe('38')
+ expect(txOut.value instanceof BigNumber).toStrictEqual(true)
+ expect(txOut.value.toString()).toStrictEqual('38')
expect(txOut.scriptPubKey).toHaveProperty('asm')
expect(txOut.scriptPubKey).toHaveProperty('hex')
expect(txOut.scriptPubKey.reqSigs).toBeGreaterThanOrEqual(1)
- expect(txOut.scriptPubKey.type).toBe('pubkeyhash')
+ expect(txOut.scriptPubKey.type).toStrictEqual('pubkeyhash')
expect(txOut.scriptPubKey.addresses.length).toBeGreaterThanOrEqual(1)
- expect(txOut.scriptPubKey.addresses[0]).toBe('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
- expect(txOut.coinbase).toBe(true)
+ expect(txOut.scriptPubKey.addresses[0]).toStrictEqual('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
+ expect(txOut.coinbase).toStrictEqual(true)
})
})
@@ -241,14 +241,21 @@ describe('masternode', () => {
for (let i = 0; i < chainTips.length; i += 1) {
const data = chainTips[i]
expect(data.height).toBeGreaterThan(0)
- expect(typeof data.hash).toBe('string')
- expect(data.hash.length).toBe(64)
+ expect(typeof data.hash).toStrictEqual('string')
+ expect(data.hash.length).toStrictEqual(64)
expect(data.branchlen).toBeGreaterThanOrEqual(0)
- expect(['invalid', 'headers-only', 'valid-headers', 'valid-fork', 'active'].includes(data.status)).toBe(true)
+ expect(['invalid', 'headers-only', 'valid-headers', 'valid-fork', 'active'].includes(data.status)).toStrictEqual(true)
}
})
})
+ describe('getdifficulty', () => {
+ it('should getDifficulty', async () => {
+ const difficulty = await client.blockchain.getDifficulty()
+ expect(difficulty).toBeGreaterThanOrEqual(0)
+ })
+ })
+
describe('getRawMempool', () => {
beforeAll(async () => {
await client.wallet.setWalletFlag(wallet.WalletFlag.AVOID_REUSE)
@@ -259,8 +266,8 @@ describe('masternode', () => {
await client.wallet.sendToAddress('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU', 0.00001)
const rawMempool: string[] = await client.blockchain.getRawMempool(false)
- expect(rawMempool.length > 0).toBe(true)
- expect(typeof rawMempool[0]).toBe('string')
+ expect(rawMempool.length > 0).toStrictEqual(true)
+ expect(typeof rawMempool[0]).toStrictEqual('string')
}, 10000)
})
@@ -270,47 +277,47 @@ describe('masternode', () => {
const rawMempool: blockchain.MempoolTx = await client.blockchain.getRawMempool(true)
const data = rawMempool[transactionId]
- expect(data.fees.base instanceof BigNumber).toBe(true)
- expect(data.fees.modified instanceof BigNumber).toBe(true)
- expect(data.fees.ancestor instanceof BigNumber).toBe(true)
- expect(data.fees.descendant instanceof BigNumber).toBe(true)
- expect(data.fees.base.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.fees.modified.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.fees.ancestor.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.fees.descendant.isGreaterThan(new BigNumber('0'))).toBe(true)
-
- expect(data.fee instanceof BigNumber).toBe(true)
- expect(data.fee.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.modifiedfee instanceof BigNumber).toBe(true)
- expect(data.modifiedfee.isGreaterThan(new BigNumber('0'))).toBe(true)
-
- expect(data.vsize instanceof BigNumber).toBe(true)
- expect(data.weight instanceof BigNumber).toBe(true)
- expect(data.height instanceof BigNumber).toBe(true)
- expect(data.time instanceof BigNumber).toBe(true)
- expect(data.vsize.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.weight.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.height.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.time.isGreaterThan(new BigNumber('0'))).toBe(true)
-
- expect(typeof data.wtxid).toBe('string')
- expect(data.depends.length >= 0).toBe(true)
- expect(data.spentby.length >= 0).toBe(true)
- expect(data['bip125-replaceable']).toBe(false)
-
- expect(data.descendantcount instanceof BigNumber).toBe(true)
- expect(data.descendantsize instanceof BigNumber).toBe(true)
- expect(data.descendantfees instanceof BigNumber).toBe(true)
- expect(data.descendantcount.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.descendantsize.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.descendantfees.isGreaterThan(new BigNumber('0'))).toBe(true)
-
- expect(data.ancestorcount instanceof BigNumber).toBe(true)
- expect(data.ancestorsize instanceof BigNumber).toBe(true)
- expect(data.ancestorfees instanceof BigNumber).toBe(true)
- expect(data.ancestorcount.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.ancestorsize.isGreaterThan(new BigNumber('0'))).toBe(true)
- expect(data.ancestorfees.isGreaterThan(new BigNumber('0'))).toBe(true)
+ expect(data.fees.base instanceof BigNumber).toStrictEqual(true)
+ expect(data.fees.modified instanceof BigNumber).toStrictEqual(true)
+ expect(data.fees.ancestor instanceof BigNumber).toStrictEqual(true)
+ expect(data.fees.descendant instanceof BigNumber).toStrictEqual(true)
+ expect(data.fees.base.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.fees.modified.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.fees.ancestor.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.fees.descendant.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+
+ expect(data.fee instanceof BigNumber).toStrictEqual(true)
+ expect(data.fee.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.modifiedfee instanceof BigNumber).toStrictEqual(true)
+ expect(data.modifiedfee.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+
+ expect(data.vsize instanceof BigNumber).toStrictEqual(true)
+ expect(data.weight instanceof BigNumber).toStrictEqual(true)
+ expect(data.height instanceof BigNumber).toStrictEqual(true)
+ expect(data.time instanceof BigNumber).toStrictEqual(true)
+ expect(data.vsize.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.weight.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.height.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.time.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+
+ expect(typeof data.wtxid).toStrictEqual('string')
+ expect(data.depends.length >= 0).toStrictEqual(true)
+ expect(data.spentby.length >= 0).toStrictEqual(true)
+ expect(data['bip125-replaceable']).toStrictEqual(false)
+
+ expect(data.descendantcount instanceof BigNumber).toStrictEqual(true)
+ expect(data.descendantsize instanceof BigNumber).toStrictEqual(true)
+ expect(data.descendantfees instanceof BigNumber).toStrictEqual(true)
+ expect(data.descendantcount.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.descendantsize.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.descendantfees.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+
+ expect(data.ancestorcount instanceof BigNumber).toStrictEqual(true)
+ expect(data.ancestorsize instanceof BigNumber).toStrictEqual(true)
+ expect(data.ancestorfees instanceof BigNumber).toStrictEqual(true)
+ expect(data.ancestorcount.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.ancestorsize.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
+ expect(data.ancestorfees.isGreaterThan(new BigNumber('0'))).toStrictEqual(true)
})
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/mining.test.ts b/packages/jellyfish-api-core/__tests__/category/mining.test.ts
index 17471d7d39..98927c7bdd 100644
--- a/packages/jellyfish-api-core/__tests__/category/mining.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/mining.test.ts
@@ -1,6 +1,8 @@
import { RegTestContainer, MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../container_adapter_client'
import waitForExpect from 'wait-for-expect'
+import { wallet } from '../../src'
+import { EstimateMode } from '../../src/category/mining'
describe('non masternode', () => {
const container = new RegTestContainer()
@@ -18,18 +20,26 @@ describe('non masternode', () => {
it('should getMintingInfo', async () => {
const info = await client.mining.getMintingInfo()
- expect(info.blocks).toBe(0)
+ expect(info.blocks).toStrictEqual(0)
expect(info.difficulty).toBeDefined()
- expect(info.isoperator).toBe(false)
- expect(info.networkhashps).toBe(0)
- expect(info.pooledtx).toBe(0)
- expect(info.chain).toBe('regtest')
- expect(info.warnings).toBe('')
+ expect(info.isoperator).toStrictEqual(false)
+ expect(info.networkhashps).toStrictEqual(0)
+ expect(info.pooledtx).toStrictEqual(0)
+ expect(info.chain).toStrictEqual('regtest')
+ expect(info.warnings).toStrictEqual('')
})
it('should getNetworkHashPerSecond', async () => {
const result = await client.mining.getNetworkHashPerSecond()
- expect(result).toBe(0)
+ expect(result).toStrictEqual(0)
+ })
+
+ it('should have an error with estimateSmartFee', async () => {
+ const result = await client.mining.estimateSmartFee(6)
+ const errors = (result.errors != null) ? result.errors : []
+ expect(errors.length).toBeGreaterThan(0)
+ expect(errors[0]).toStrictEqual('Insufficient data or no feerate found')
+ expect(result.feerate).toBeUndefined()
})
})
@@ -57,21 +67,21 @@ describe('masternode', () => {
expect(info.blocks).toBeGreaterThan(0)
expect(info.currentblockweight).toBeGreaterThan(0)
- expect(info.currentblocktx).toBe(0)
+ expect(info.currentblocktx).toStrictEqual(0)
expect(info.difficulty).toBeDefined()
- expect(info.isoperator).toBe(true)
+ expect(info.isoperator).toStrictEqual(true)
expect(info.masternodeid).toBeDefined()
expect(info.masternodeoperator).toBeDefined()
- expect(info.masternodestate).toBe('ENABLED')
- expect(info.generate).toBe(true)
- expect(info.mintedblocks).toBe(0)
+ expect(info.masternodestate).toStrictEqual('ENABLED')
+ expect(info.generate).toStrictEqual(true)
+ expect(info.mintedblocks).toStrictEqual(0)
expect(info.networkhashps).toBeGreaterThan(0)
- expect(info.pooledtx).toBe(0)
- expect(info.chain).toBe('regtest')
- expect(info.warnings).toBe('')
+ expect(info.pooledtx).toStrictEqual(0)
+ expect(info.chain).toStrictEqual('regtest')
+ expect(info.warnings).toStrictEqual('')
})
it('should getNetworkHashPerSecond', async () => {
@@ -93,21 +103,55 @@ describe('masternode', () => {
expect(info.blocks).toBeGreaterThan(0)
expect(info.currentblockweight).toBeGreaterThan(0)
- expect(info.currentblocktx).toBe(0)
+ expect(info.currentblocktx).toStrictEqual(0)
expect(info.difficulty).toBeDefined()
- expect(info.isoperator).toBe(true)
+ expect(info.isoperator).toStrictEqual(true)
expect(mn1.masternodeid).toBeDefined()
expect(mn1.masternodeoperator).toBeDefined()
- expect(mn1.masternodestate).toBe('ENABLED')
- expect(mn1.generate).toBe(true)
- expect(mn1.mintedblocks).toBe(0)
- expect(mn1.lastblockcreationattempt).toBe('0')
+ expect(mn1.masternodestate).toStrictEqual('ENABLED')
+ expect(mn1.generate).toStrictEqual(true)
+ expect(mn1.mintedblocks).toStrictEqual(0)
+ expect(mn1.lastblockcreationattempt).toStrictEqual('0')
expect(info.networkhashps).toBeGreaterThan(0)
- expect(info.pooledtx).toBe(0)
- expect(info.chain).toBe('regtest')
- expect(info.warnings).toBe('')
+ expect(info.pooledtx).toStrictEqual(0)
+ expect(info.chain).toStrictEqual('regtest')
+ expect(info.warnings).toStrictEqual('')
+ })
+})
+
+describe('estimatesmartfees', () => {
+ const container = new MasterNodeRegTestContainer()
+ const client = new ContainerAdapterClient(container)
+
+ beforeAll(async () => {
+ await container.start()
+ await container.waitForReady()
+ await container.waitForWalletCoinbaseMaturity()
+ await container.waitForBlock(125)
+ await client.wallet.setWalletFlag(wallet.WalletFlag.AVOID_REUSE)
+ })
+
+ afterAll(async () => {
+ await container.stop()
+ })
+
+ it('should have estimated smart fees', async () => {
+ await waitForExpect(async () => {
+ for (let i = 0; i < 20; i++) {
+ for (let x = 0; x < 20; x++) {
+ const address = await client.wallet.getNewAddress()
+ await client.wallet.sendToAddress(address, 0.1, { subtractFeeFromAmount: true })
+ }
+ await container.generate(1)
+ }
+ })
+
+ const result = await client.mining.estimateSmartFee(6, EstimateMode.ECONOMICAL)
+ expect(result.errors).toBeUndefined()
+ expect(result.blocks).toBeGreaterThan(0)
+ expect(result.feerate).toBeGreaterThan(0)
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/net.test.ts b/packages/jellyfish-api-core/__tests__/category/net.test.ts
index 07e4f4df83..a812cfddc0 100644
--- a/packages/jellyfish-api-core/__tests__/category/net.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/net.test.ts
@@ -23,23 +23,23 @@ describe('non masternode', () => {
it('should getNetworkInfo', async () => {
const info: net.NetworkInfo = await client.net.getNetworkInfo()
expect(info.version).toBeGreaterThanOrEqual(0)
- expect(typeof info.subversion).toBe('string')
+ expect(typeof info.subversion).toStrictEqual('string')
expect(info.protocolversion).toBeGreaterThanOrEqual(0)
- expect(typeof info.localservices).toBe('string')
- expect(typeof info.localrelay).toBe('boolean')
+ expect(typeof info.localservices).toStrictEqual('string')
+ expect(typeof info.localrelay).toStrictEqual('boolean')
expect(info.timeoffset).toBeGreaterThanOrEqual(0)
expect(info.connections).toBeGreaterThanOrEqual(0)
- expect(typeof info.networkactive).toBe('boolean')
+ expect(typeof info.networkactive).toStrictEqual('boolean')
const networks = info.networks
for (let i = 0; i < networks.length; i += 1) {
const network = networks[i]
expect(['ipv4', 'ipv6', 'onion']).toContain(network.name)
- expect(typeof network.limited).toBe('boolean')
- expect(typeof network.reachable).toBe('boolean')
- expect(typeof network.proxy).toBe('string')
- expect(typeof network.proxy_randomize_credentials).toBe('boolean')
+ expect(typeof network.limited).toStrictEqual('boolean')
+ expect(typeof network.reachable).toStrictEqual('boolean')
+ expect(typeof network.proxy).toStrictEqual('string')
+ expect(typeof network.proxy_randomize_credentials).toStrictEqual('boolean')
}
expect(info.relayfee).toBeGreaterThanOrEqual(0)
@@ -49,13 +49,13 @@ describe('non masternode', () => {
for (let i = 0; i < localaddresses.length; i += 1) {
const localaddress = localaddresses[i]
- expect(localaddress.address).toBe('string')
+ expect(localaddress.address).toStrictEqual('string')
expect(localaddress.port).toBeGreaterThanOrEqual(0)
expect(localaddress.port).toBeLessThanOrEqual(65535)
expect(localaddress.score).toBeGreaterThanOrEqual(0)
}
- expect(typeof info.warnings).toBe('string')
+ expect(typeof info.warnings).toStrictEqual('string')
})
})
@@ -81,23 +81,23 @@ describe('masternode', () => {
it('should getNetworkInfo', async () => {
const info: net.NetworkInfo = await client.net.getNetworkInfo()
expect(info.version).toBeGreaterThanOrEqual(0)
- expect(typeof info.subversion).toBe('string')
+ expect(typeof info.subversion).toStrictEqual('string')
expect(info.protocolversion).toBeGreaterThanOrEqual(0)
- expect(typeof info.localservices).toBe('string')
- expect(typeof info.localrelay).toBe('boolean')
+ expect(typeof info.localservices).toStrictEqual('string')
+ expect(typeof info.localrelay).toStrictEqual('boolean')
expect(info.timeoffset).toBeGreaterThanOrEqual(0)
expect(info.connections).toBeGreaterThanOrEqual(0)
- expect(typeof info.networkactive).toBe('boolean')
+ expect(typeof info.networkactive).toStrictEqual('boolean')
const networks = info.networks
for (let i = 0; i < networks.length; i += 1) {
const network = networks[i]
expect(['ipv4', 'ipv6', 'onion']).toContain(network.name)
- expect(typeof network.limited).toBe('boolean')
- expect(typeof network.reachable).toBe('boolean')
- expect(typeof network.proxy).toBe('string')
- expect(typeof network.proxy_randomize_credentials).toBe('boolean')
+ expect(typeof network.limited).toStrictEqual('boolean')
+ expect(typeof network.reachable).toStrictEqual('boolean')
+ expect(typeof network.proxy).toStrictEqual('string')
+ expect(typeof network.proxy_randomize_credentials).toStrictEqual('boolean')
}
expect(info.relayfee).toBeGreaterThanOrEqual(0)
@@ -107,12 +107,12 @@ describe('masternode', () => {
for (let i = 0; i < localaddresses.length; i += 1) {
const localaddress = localaddresses[i]
- expect(localaddress.address).toBe('string')
+ expect(localaddress.address).toStrictEqual('string')
expect(localaddress.port).toBeGreaterThanOrEqual(0)
expect(localaddress.port).toBeLessThanOrEqual(65535)
expect(localaddress.score).toBeGreaterThanOrEqual(0)
}
- expect(typeof info.warnings).toBe('string')
+ expect(typeof info.warnings).toStrictEqual('string')
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/poolpair.test.ts b/packages/jellyfish-api-core/__tests__/category/poolpair.test.ts
index 9fc91bfe79..4156a5e9c8 100644
--- a/packages/jellyfish-api-core/__tests__/category/poolpair.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/poolpair.test.ts
@@ -72,7 +72,7 @@ describe('masternode', () => {
'*': ['10@DFI', '200@DDAI']
}, shareAddress)
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
})
it('should addPoolLiquidity with specific input token address', async () => {
@@ -88,7 +88,7 @@ describe('masternode', () => {
[tokenBAddress]: '100@DDAI'
}, shareAddress)
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
})
it('should addPoolLiquidity with utxos', async () => {
@@ -124,7 +124,7 @@ describe('masternode', () => {
// '*': ['10@DFI', '200@DDAI']
// }, shareAddress, { utxos: [{ txid: utxo.txid, vout: 0 }] })
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
})
it('should fail while addPoolLiquidity with utxos which does not include account owner', async () => {
@@ -155,7 +155,7 @@ describe('masternode', () => {
'*': ['10@DFI', '200@DSWAP']
}, shareAddress)
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
await container.generate(1)
}
@@ -177,11 +177,11 @@ describe('masternode', () => {
for (const k in poolShares) {
const data = poolShares[k]
- expect(typeof data.poolID).toBe('string')
- expect(typeof data.owner).toBe('string')
- expect(data['%'] instanceof BigNumber).toBe(true)
- expect(data.amount instanceof BigNumber).toBe(true)
- expect(data.totalLiquidity instanceof BigNumber).toBe(true)
+ expect(typeof data.poolID).toStrictEqual('string')
+ expect(typeof data.owner).toStrictEqual('string')
+ expect(data['%'] instanceof BigNumber).toStrictEqual(true)
+ expect(data.amount instanceof BigNumber).toStrictEqual(true)
+ expect(data.totalLiquidity instanceof BigNumber).toStrictEqual(true)
}
})
@@ -193,7 +193,7 @@ describe('masternode', () => {
}
const poolShares = await client.poolpair.listPoolShares(pagination)
- expect(Object.keys(poolShares).length).toBe(0)
+ expect(Object.keys(poolShares).length).toStrictEqual(0)
})
it('should listPoolShares with pagination limit', async () => {
@@ -204,7 +204,7 @@ describe('masternode', () => {
}
const poolShares = await client.poolpair.listPoolShares(pagination)
- expect(Object.keys(poolShares).length).toBe(2)
+ expect(Object.keys(poolShares).length).toStrictEqual(2)
})
it('should listPoolPairs with verbose false', async () => {
@@ -217,9 +217,9 @@ describe('masternode', () => {
for (const k in poolShares) {
const data = poolShares[k]
- expect(typeof data.poolID).toBe('string')
- expect(typeof data.owner).toBe('string')
- expect(data['%'] instanceof BigNumber).toBe(true)
+ expect(typeof data.poolID).toStrictEqual('string')
+ expect(typeof data.owner).toStrictEqual('string')
+ expect(data['%'] instanceof BigNumber).toStrictEqual(true)
}
})
@@ -233,11 +233,11 @@ describe('masternode', () => {
for (const k in poolShares) {
const data = poolShares[k]
- expect(typeof data.poolID).toBe('string')
- expect(typeof data.owner).toBe('string')
- expect(data['%'] instanceof BigNumber).toBe(true)
- expect(data.amount instanceof BigNumber).toBe(true)
- expect(data.totalLiquidity instanceof BigNumber).toBe(true)
+ expect(typeof data.poolID).toStrictEqual('string')
+ expect(typeof data.owner).toStrictEqual('string')
+ expect(data['%'] instanceof BigNumber).toStrictEqual(true)
+ expect(data.amount instanceof BigNumber).toStrictEqual(true)
+ expect(data.totalLiquidity instanceof BigNumber).toStrictEqual(true)
}
})
})
@@ -253,21 +253,21 @@ describe('masternode', () => {
for (const k in poolpair) {
const data = poolpair[k]
- expect(data.symbol).toBe('DFI-DBCH')
- expect(data.name).toBe('Default Defi token-DBCH')
- expect(data.status).toBe(true)
- expect(typeof data.idTokenA).toBe('string')
- expect(typeof data.idTokenB).toBe('string')
- expect(data.reserveA instanceof BigNumber).toBe(true)
- expect(data.reserveB instanceof BigNumber).toBe(true)
- expect(typeof data['reserveA/reserveB']).toBe('string')
- expect(typeof data['reserveB/reserveA']).toBe('string')
- expect(data.tradeEnabled).toBe(false)
- expect(data.blockCommissionA instanceof BigNumber).toBe(true)
- expect(data.blockCommissionB instanceof BigNumber).toBe(true)
- expect(data.rewardPct instanceof BigNumber).toBe(true)
- expect(typeof data.creationTx).toBe('string')
- expect(data.creationHeight instanceof BigNumber).toBe(true)
+ expect(data.symbol).toStrictEqual('DFI-DBCH')
+ expect(data.name).toStrictEqual('Default Defi token-DBCH')
+ expect(data.status).toStrictEqual(true)
+ expect(typeof data.idTokenA).toStrictEqual('string')
+ expect(typeof data.idTokenB).toStrictEqual('string')
+ expect(data.reserveA instanceof BigNumber).toStrictEqual(true)
+ expect(data.reserveB instanceof BigNumber).toStrictEqual(true)
+ expect(typeof data['reserveA/reserveB']).toStrictEqual('string')
+ expect(typeof data['reserveB/reserveA']).toStrictEqual('string')
+ expect(data.tradeEnabled).toStrictEqual(false)
+ expect(data.blockCommissionA instanceof BigNumber).toStrictEqual(true)
+ expect(data.blockCommissionB instanceof BigNumber).toStrictEqual(true)
+ expect(data.rewardPct instanceof BigNumber).toStrictEqual(true)
+ expect(typeof data.creationTx).toStrictEqual('string')
+ expect(data.creationHeight instanceof BigNumber).toStrictEqual(true)
}
})
@@ -276,11 +276,11 @@ describe('masternode', () => {
for (const k in poolpair) {
const data = poolpair[k]
- expect(data.symbol).toBe('DFI-DBCH')
- expect(data.name).toBe('Default Defi token-DBCH')
- expect(data.status).toBe(true)
- expect(typeof data.idTokenA).toBe('string')
- expect(typeof data.idTokenB).toBe('string')
+ expect(data.symbol).toStrictEqual('DFI-DBCH')
+ expect(data.name).toStrictEqual('Default Defi token-DBCH')
+ expect(data.status).toStrictEqual(true)
+ expect(typeof data.idTokenA).toStrictEqual('string')
+ expect(typeof data.idTokenB).toStrictEqual('string')
}
})
@@ -310,49 +310,49 @@ describe('masternode', () => {
const poolpair = poolpairs[k]
if (poolpair.symbol === 'DFI-DETH') {
- expect(poolpair.name).toBe('Default Defi token-DETH')
- expect(poolpair.status).toBe(true)
- expect(poolpair.commission.toString()).toBe(new BigNumber(0.001).toString())
+ expect(poolpair.name).toStrictEqual('Default Defi token-DETH')
+ expect(poolpair.status).toStrictEqual(true)
+ expect(poolpair.commission.toString()).toStrictEqual(new BigNumber(0.001).toString())
assertions += 1
}
if (poolpair.symbol === 'DFI-DXRP') {
- expect(poolpair.name).toBe('Default Defi token-DXRP')
- expect(poolpair.status).toBe(true)
- expect(poolpair.commission.toString()).toBe(new BigNumber(0.003).toString())
+ expect(poolpair.name).toStrictEqual('Default Defi token-DXRP')
+ expect(poolpair.status).toStrictEqual(true)
+ expect(poolpair.commission.toString()).toStrictEqual(new BigNumber(0.003).toString())
assertions += 1
}
if (poolpair.symbol === 'DFI-DUSD') {
- expect(poolpair.name).toBe('Default Defi token-DUSDT')
- expect(poolpair.status).toBe(false)
- expect(poolpair.commission.toString()).toBe(new BigNumber(0).toString())
+ expect(poolpair.name).toStrictEqual('Default Defi token-DUSDT')
+ expect(poolpair.status).toStrictEqual(false)
+ expect(poolpair.commission.toString()).toStrictEqual(new BigNumber(0).toString())
assertions += 1
}
- expect(poolpair.totalLiquidity instanceof BigNumber).toBe(true)
- expect(typeof poolpair.ownerAddress).toBe('string')
- expect(typeof poolpair.idTokenA).toBe('string')
- expect(typeof poolpair.idTokenB).toBe('string')
- expect(poolpair.reserveA instanceof BigNumber).toBe(true)
- expect(poolpair.reserveB instanceof BigNumber).toBe(true)
+ expect(poolpair.totalLiquidity instanceof BigNumber).toStrictEqual(true)
+ expect(typeof poolpair.ownerAddress).toStrictEqual('string')
+ expect(typeof poolpair.idTokenA).toStrictEqual('string')
+ expect(typeof poolpair.idTokenB).toStrictEqual('string')
+ expect(poolpair.reserveA instanceof BigNumber).toStrictEqual(true)
+ expect(poolpair.reserveB instanceof BigNumber).toStrictEqual(true)
if (poolpair['reserveA/reserveB'] instanceof BigNumber && poolpair['reserveB/reserveA'] instanceof BigNumber) {
- expect(poolpair.tradeEnabled).toBe(true)
+ expect(poolpair.tradeEnabled).toStrictEqual(true)
} else {
- expect(poolpair['reserveA/reserveB']).toBe('0')
- expect(poolpair['reserveB/reserveA']).toBe('0')
- expect(poolpair.tradeEnabled).toBe(false)
+ expect(poolpair['reserveA/reserveB']).toStrictEqual('0')
+ expect(poolpair['reserveB/reserveA']).toStrictEqual('0')
+ expect(poolpair.tradeEnabled).toStrictEqual(false)
}
- expect(poolpair.blockCommissionA instanceof BigNumber).toBe(true)
- expect(poolpair.blockCommissionB instanceof BigNumber).toBe(true)
- expect(poolpair.rewardPct instanceof BigNumber).toBe(true)
- expect(typeof poolpair.creationTx).toBe('string')
- expect(poolpair.creationHeight instanceof BigNumber).toBe(true)
+ expect(poolpair.blockCommissionA instanceof BigNumber).toStrictEqual(true)
+ expect(poolpair.blockCommissionB instanceof BigNumber).toStrictEqual(true)
+ expect(poolpair.rewardPct instanceof BigNumber).toStrictEqual(true)
+ expect(typeof poolpair.creationTx).toStrictEqual('string')
+ expect(poolpair.creationHeight instanceof BigNumber).toStrictEqual(true)
}
- expect(assertions).toBe(3)
+ expect(assertions).toStrictEqual(3)
})
it('should listPoolPairs with pagination and return an empty object as out of range', async () => {
@@ -363,7 +363,7 @@ describe('masternode', () => {
}
const poolpairs = await client.poolpair.listPoolPairs(pagination)
- expect(Object.keys(poolpairs).length).toBe(0)
+ expect(Object.keys(poolpairs).length).toStrictEqual(0)
})
it('should listPoolPairs with pagination limit', async () => {
@@ -374,7 +374,7 @@ describe('masternode', () => {
}
const poolpairs = await client.poolpair.listPoolPairs(pagination)
- expect(Object.keys(poolpairs).length).toBe(2)
+ expect(Object.keys(poolpairs).length).toStrictEqual(2)
})
it('should listPoolPairs with verbose false', async () => {
@@ -388,11 +388,11 @@ describe('masternode', () => {
for (const k in poolpairs) {
const poolpair = poolpairs[k]
- expect(typeof poolpair.symbol).toBe('string')
- expect(typeof poolpair.name).toBe('string')
- expect(typeof poolpair.status).toBe('boolean')
- expect(typeof poolpair.idTokenA).toBe('string')
- expect(typeof poolpair.idTokenB).toBe('string')
+ expect(typeof poolpair.symbol).toStrictEqual('string')
+ expect(typeof poolpair.name).toStrictEqual('string')
+ expect(typeof poolpair.status).toStrictEqual('boolean')
+ expect(typeof poolpair.idTokenA).toStrictEqual('string')
+ expect(typeof poolpair.idTokenB).toStrictEqual('string')
}
})
})
@@ -416,37 +416,37 @@ describe('masternode', () => {
ownerAddress: address
}
const data = await client.poolpair.createPoolPair(metadata)
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
await container.generate(1)
const poolpairsAfter = await client.poolpair.listPoolPairs()
- expect(Object.keys(poolpairsAfter).length).toBe(poolpairsLengthBefore + 1)
+ expect(Object.keys(poolpairsAfter).length).toStrictEqual(poolpairsLengthBefore + 1)
for (const k in poolpairsAfter) {
const poolpair = poolpairsAfter[k]
if (poolpair.name === 'Default Defi token-DBTC') {
- expect(poolpair.symbol).toBe(`${metadata.tokenA}-${metadata.tokenB}`)
- expect(poolpair.status).toBe(metadata.status)
- expect(poolpair.commission.toString()).toBe(new BigNumber(metadata.commission).toString())
- expect(poolpair.ownerAddress).toBe(metadata.ownerAddress)
- expect(poolpair.totalLiquidity instanceof BigNumber).toBe(true)
- expect(typeof poolpair.idTokenA).toBe('string')
- expect(typeof poolpair.idTokenB).toBe('string')
- expect(poolpair.reserveA instanceof BigNumber).toBe(true)
- expect(poolpair.reserveB instanceof BigNumber).toBe(true)
- expect(typeof poolpair['reserveA/reserveB']).toBe('string')
- expect(typeof poolpair['reserveB/reserveA']).toBe('string')
- expect(poolpair.tradeEnabled).toBe(false)
- expect(poolpair.blockCommissionA instanceof BigNumber).toBe(true)
- expect(poolpair.blockCommissionB instanceof BigNumber).toBe(true)
- expect(poolpair.rewardPct instanceof BigNumber).toBe(true)
- expect(typeof poolpair.creationTx).toBe('string')
- expect(poolpair.creationHeight instanceof BigNumber).toBe(true)
+ expect(poolpair.symbol).toStrictEqual(`${metadata.tokenA}-${metadata.tokenB}`)
+ expect(poolpair.status).toStrictEqual(metadata.status)
+ expect(poolpair.commission.toString()).toStrictEqual(new BigNumber(metadata.commission).toString())
+ expect(poolpair.ownerAddress).toStrictEqual(metadata.ownerAddress)
+ expect(poolpair.totalLiquidity instanceof BigNumber).toStrictEqual(true)
+ expect(typeof poolpair.idTokenA).toStrictEqual('string')
+ expect(typeof poolpair.idTokenB).toStrictEqual('string')
+ expect(poolpair.reserveA instanceof BigNumber).toStrictEqual(true)
+ expect(poolpair.reserveB instanceof BigNumber).toStrictEqual(true)
+ expect(typeof poolpair['reserveA/reserveB']).toStrictEqual('string')
+ expect(typeof poolpair['reserveB/reserveA']).toStrictEqual('string')
+ expect(poolpair.tradeEnabled).toStrictEqual(false)
+ expect(poolpair.blockCommissionA instanceof BigNumber).toStrictEqual(true)
+ expect(poolpair.blockCommissionB instanceof BigNumber).toStrictEqual(true)
+ expect(poolpair.rewardPct instanceof BigNumber).toStrictEqual(true)
+ expect(typeof poolpair.creationTx).toStrictEqual('string')
+ expect(poolpair.creationHeight instanceof BigNumber).toStrictEqual(true)
assertions += 1
}
}
- expect(assertions).toBe(1)
+ expect(assertions).toStrictEqual(1)
})
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/rawtx.test.ts b/packages/jellyfish-api-core/__tests__/category/rawtx.test.ts
index 539579c0ce..27fdb9d352 100644
--- a/packages/jellyfish-api-core/__tests__/category/rawtx.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/rawtx.test.ts
@@ -39,27 +39,27 @@ describe('createRawTransaction', () => {
const unsigned: string = await client.rawtx.createRawTransaction(inputs, outputs)
// Version
- expect(unsigned.substr(0, 8)).toBe('04000000')
+ expect(unsigned.substr(0, 8)).toStrictEqual('04000000')
// Vin
- expect(unsigned.substr(8, 2)).toBe('01')
- expect(unsigned.substr(10, 64)).toBe(
+ expect(unsigned.substr(8, 2)).toStrictEqual('01')
+ expect(unsigned.substr(10, 64)).toStrictEqual(
Buffer.from(txid, 'hex').reverse().toString('hex')
)
- expect(unsigned.substr(74, 8)).toBe('00000000')
- expect(unsigned.substr(82, 2)).toBe('00')
- expect(unsigned.substr(84, 8)).toBe('ffffffff')
+ expect(unsigned.substr(74, 8)).toStrictEqual('00000000')
+ expect(unsigned.substr(82, 2)).toStrictEqual('00')
+ expect(unsigned.substr(84, 8)).toStrictEqual('ffffffff')
// Vout
- expect(unsigned.substr(92, 2)).toBe('01')
- expect(unsigned.substr(94, 16)).toBe('0065cd1d00000000')
- expect(unsigned.substr(110, 2)).toBe('16')
- expect(unsigned.substr(112, 2)).toBe('00') // OP_0
- expect(unsigned.substr(114, 2)).toBe('14')
- expect(unsigned.substr(116, 40)).toBe('4ab4391ce5a732e36139e72d79a28e01b7b08034') // PKH
- expect(unsigned.substr(156, 2)).toBe('00') // DCT_ID
+ expect(unsigned.substr(92, 2)).toStrictEqual('01')
+ expect(unsigned.substr(94, 16)).toStrictEqual('0065cd1d00000000')
+ expect(unsigned.substr(110, 2)).toStrictEqual('16')
+ expect(unsigned.substr(112, 2)).toStrictEqual('00') // OP_0
+ expect(unsigned.substr(114, 2)).toStrictEqual('14')
+ expect(unsigned.substr(116, 40)).toStrictEqual('4ab4391ce5a732e36139e72d79a28e01b7b08034') // PKH
+ expect(unsigned.substr(156, 2)).toStrictEqual('00') // DCT_ID
// LockTime
- expect(unsigned.substr(158, 8)).toBe('00000000')
+ expect(unsigned.substr(158, 8)).toStrictEqual('00000000')
- expect(unsigned.length).toBe(166)
+ expect(unsigned.length).toStrictEqual(166)
})
it('should createRawTransaction() with locktime 1000', async () => {
@@ -73,13 +73,13 @@ describe('createRawTransaction', () => {
locktime: 1000
})
- expect(unsigned.substr(0, 84)).toBe(
+ expect(unsigned.substr(0, 84)).toStrictEqual(
'0400000001' + Buffer.from(txid, 'hex').reverse().toString('hex') + '0000000000'
)
- expect(unsigned.substr(84, 8)).toBe('feffffff')
- expect(unsigned.substr(92, 66)).toBe('010065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b0803400')
- expect(unsigned.substr(158, 8)).toBe('e8030000')
- expect(unsigned.length).toBe(166)
+ expect(unsigned.substr(84, 8)).toStrictEqual('feffffff')
+ expect(unsigned.substr(92, 66)).toStrictEqual('010065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b0803400')
+ expect(unsigned.substr(158, 8)).toStrictEqual('e8030000')
+ expect(unsigned.length).toStrictEqual(166)
})
it('should createRawTransaction() with replaceable = true', async () => {
@@ -93,12 +93,12 @@ describe('createRawTransaction', () => {
replaceable: true
})
- expect(unsigned.substr(0, 84)).toBe(
+ expect(unsigned.substr(0, 84)).toStrictEqual(
'0400000001' + Buffer.from(txid, 'hex').reverse().toString('hex') + '0000000000'
)
- expect(unsigned.substr(84, 8)).toBe('fdffffff')
- expect(unsigned.substr(92, 74)).toBe('010065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340000000000')
- expect(unsigned.length).toBe(166)
+ expect(unsigned.substr(84, 8)).toStrictEqual('fdffffff')
+ expect(unsigned.substr(92, 74)).toStrictEqual('010065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340000000000')
+ expect(unsigned.length).toStrictEqual(166)
})
})
@@ -113,9 +113,9 @@ describe('signRawTransactionWithKey', () => {
const unsigned = await client.rawtx.createRawTransaction(inputs, outputs)
const signed = await client.rawtx.signRawTransactionWithKey(unsigned, [input.privKey])
- expect(signed.complete).toBe(true)
- expect(signed.hex.substr(0, 14)).toBe('04000000000101')
- expect(signed.hex.substr(86, 78)).toBe('00ffffffff010065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340002')
+ expect(signed.complete).toStrictEqual(true)
+ expect(signed.hex.substr(0, 14)).toStrictEqual('04000000000101')
+ expect(signed.hex.substr(86, 78)).toStrictEqual('00ffffffff010065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340002')
expect(signed.hex).toContain('012103987aec2e508e124468f0f07a836d185b329026e7aaf75be48cf12be8f18cbe8100000000')
})
@@ -133,9 +133,9 @@ describe('signRawTransactionWithKey', () => {
const unsigned = await client.rawtx.createRawTransaction(inputs, outputs)
const signed = await client.rawtx.signRawTransactionWithKey(unsigned, [input.privKey])
- expect(signed.complete).toBe(true)
- expect(signed.hex.substr(0, 14)).toBe('04000000000101')
- expect(signed.hex.substr(86, 142)).toBe('00ffffffff020065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340080ce341d0000000016001425a544c073cbca4e88d59f95ccd52e584c7e6a820002')
+ expect(signed.complete).toStrictEqual(true)
+ expect(signed.hex.substr(0, 14)).toStrictEqual('04000000000101')
+ expect(signed.hex.substr(86, 142)).toStrictEqual('00ffffffff020065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340080ce341d0000000016001425a544c073cbca4e88d59f95ccd52e584c7e6a820002')
expect(signed.hex).toContain('012103987aec2e508e124468f0f07a836d185b329026e7aaf75be48cf12be8f18cbe8100000000')
})
@@ -156,7 +156,7 @@ describe('signRawTransactionWithKey', () => {
}
function exceptSignature (signed: SignRawTxWithKeyResult): void {
- expect(signed.complete).toBe(true)
+ expect(signed.complete).toStrictEqual(true)
expect(signed.hex.length).toBeGreaterThanOrEqual(446)
expect(signed.hex.length).toBeLessThanOrEqual(448)
}
@@ -204,9 +204,9 @@ describe('testMempoolAccept', () => {
const signed = '0400000000010193c90783761bf94838ced5a8313eb355c3bdd053cdbdbb3f9e0f3dbc3243609b0000000000ffffffff020065cd1d000000001600144ab4391ce5a732e36139e72d79a28e01b7b080340080ce341d0000000016001425a544c073cbca4e88d59f95ccd52e584c7e6a82000247304402201142c461b7b52323654710b14074928dd8e623d75141f9eb8c2132b7cb2d47c202202883fde993e1ecf0cf3955235522e9fe948b523b568d0e6b427f83c6f1b3efd9012103987aec2e508e124468f0f07a836d185b329026e7aaf75be48cf12be8f18cbe8100000000'
const result = await client.rawtx.testMempoolAccept(signed)
- expect(result.txid).toBe('5749ad89256b50786a02d4527621a4fc7fa6acc5a3b289841112628ff3a4990a')
- expect(result.allowed).toBe(false)
- expect(result['reject-reason']).toBe('missing-inputs')
+ expect(result.txid).toStrictEqual('5749ad89256b50786a02d4527621a4fc7fa6acc5a3b289841112628ff3a4990a')
+ expect(result.allowed).toStrictEqual(false)
+ expect(result['reject-reason']).toStrictEqual('missing-inputs')
})
async function testMempoolAcceptFees (fees?: BigNumber): Promise {
@@ -225,29 +225,29 @@ describe('testMempoolAccept', () => {
it('testMempoolAccept() should succeed with any fees', async () => {
const result = await testMempoolAcceptFees()
- expect(result.allowed).toBe(true)
+ expect(result.allowed).toStrictEqual(true)
})
it('testMempoolAccept() should succeed with high fees rate', async () => {
const result = await testMempoolAcceptFees(new BigNumber('10.0'))
- expect(result.allowed).toBe(true)
+ expect(result.allowed).toStrictEqual(true)
})
it('testMempoolAccept() should succeed just above expected fees', async () => {
const result = await testMempoolAcceptFees(new BigNumber('4.6'))
- expect(result.allowed).toBe(true)
+ expect(result.allowed).toStrictEqual(true)
})
it('testMempoolAccept() should fail with low fee rate', async () => {
const result = await testMempoolAcceptFees(new BigNumber('4.5'))
- expect(result.allowed).toBe(false)
- expect(result['reject-reason']).toBe('256: absurdly-high-fee')
+ expect(result.allowed).toStrictEqual(false)
+ expect(result['reject-reason']).toStrictEqual('256: absurdly-high-fee')
})
it('testMempoolAccept() should fail with extreme low fee rate', async () => {
const result = await testMempoolAcceptFees(new BigNumber('0.01'))
- expect(result.allowed).toBe(false)
- expect(result['reject-reason']).toBe('256: absurdly-high-fee')
+ expect(result.allowed).toStrictEqual(false)
+ expect(result['reject-reason']).toStrictEqual('256: absurdly-high-fee')
})
})
@@ -265,6 +265,6 @@ describe('sendRawTransaction', () => {
const txid = await client.rawtx.sendRawTransaction(signed.hex)
const tx = await container.call('getrawtransaction', [txid, true])
- expect(tx.txid).toBe(txid)
+ expect(tx.txid).toStrictEqual(txid)
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/token.test.ts b/packages/jellyfish-api-core/__tests__/category/token.test.ts
index 36bc3013c9..6223d9dac6 100644
--- a/packages/jellyfish-api-core/__tests__/category/token.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/token.test.ts
@@ -25,22 +25,22 @@ describe('non masternode', () => {
const token = await client.token.listTokens()
const data = token['0']
- expect(data.symbol).toBe('DFI')
- expect(data.symbolKey).toBe('DFI')
- expect(data.name).toBe('Default Defi token')
- expect(data.decimal).toBe(8)
- expect(data.limit).toBe(0)
- expect(data.mintable).toBe(false)
- expect(data.tradeable).toBe(true)
- expect(data.isDAT).toBe(true)
- expect(data.isLPS).toBe(false)
- expect(data.finalized).toBe(true)
- expect(data.minted).toBe(0)
- expect(data.creationTx).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(data.creationHeight).toBe(0)
- expect(data.destructionTx).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(data.destructionHeight).toBe(-1)
- expect(data.collateralAddress).toBe('')
+ expect(data.symbol).toStrictEqual('DFI')
+ expect(data.symbolKey).toStrictEqual('DFI')
+ expect(data.name).toStrictEqual('Default Defi token')
+ expect(data.decimal).toStrictEqual(8)
+ expect(data.limit).toStrictEqual(0)
+ expect(data.mintable).toStrictEqual(false)
+ expect(data.tradeable).toStrictEqual(true)
+ expect(data.isDAT).toStrictEqual(true)
+ expect(data.isLPS).toStrictEqual(false)
+ expect(data.finalized).toStrictEqual(true)
+ expect(data.minted).toStrictEqual(0)
+ expect(data.creationTx).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(data.creationHeight).toStrictEqual(0)
+ expect(data.destructionTx).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(data.destructionHeight).toStrictEqual(-1)
+ expect(data.collateralAddress).toStrictEqual('')
})
it('should listTokens with pagination and return an empty object as out of range', async () => {
@@ -52,7 +52,7 @@ describe('non masternode', () => {
}
const token = await client.token.listTokens(pagination)
- expect(Object.keys(token).length).toBe(0)
+ expect(Object.keys(token).length).toStrictEqual(0)
})
})
@@ -70,9 +70,9 @@ describe('non masternode', () => {
const tokens = await client.token.listTokens(pagination, false)
const data = tokens['0']
- expect(data.symbol).toBe('DFI')
- expect(data.symbolKey).toBe('DFI')
- expect(data.name).toBe('Default Defi token')
+ expect(data.symbol).toStrictEqual('DFI')
+ expect(data.symbolKey).toStrictEqual('DFI')
+ expect(data.name).toStrictEqual('Default Defi token')
})
})
@@ -86,22 +86,22 @@ describe('non masternode', () => {
const token = await client.token.getToken('DFI')
const data = token['0']
- expect(data.symbol).toBe('DFI')
- expect(data.symbolKey).toBe('DFI')
- expect(data.name).toBe('Default Defi token')
- expect(data.decimal).toBe(8)
- expect(data.limit).toBe(0)
- expect(data.mintable).toBe(false)
- expect(data.tradeable).toBe(true)
- expect(data.isDAT).toBe(true)
- expect(data.isLPS).toBe(false)
- expect(data.finalized).toBe(true)
- expect(data.minted).toBe(0)
- expect(data.creationTx).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(data.creationHeight).toBe(0)
- expect(data.destructionTx).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(data.destructionHeight).toBe(-1)
- expect(data.collateralAddress).toBe('')
+ expect(data.symbol).toStrictEqual('DFI')
+ expect(data.symbolKey).toStrictEqual('DFI')
+ expect(data.name).toStrictEqual('Default Defi token')
+ expect(data.decimal).toStrictEqual(8)
+ expect(data.limit).toStrictEqual(0)
+ expect(data.mintable).toStrictEqual(false)
+ expect(data.tradeable).toStrictEqual(true)
+ expect(data.isDAT).toStrictEqual(true)
+ expect(data.isLPS).toStrictEqual(false)
+ expect(data.finalized).toStrictEqual(true)
+ expect(data.minted).toStrictEqual(0)
+ expect(data.creationTx).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(data.creationHeight).toStrictEqual(0)
+ expect(data.destructionTx).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(data.destructionHeight).toStrictEqual(-1)
+ expect(data.collateralAddress).toStrictEqual('')
})
})
})
@@ -137,7 +137,7 @@ describe('masternode', () => {
it('should createToken', async () => {
const tokensBefore = await client.token.listTokens()
let numberOfTokens = Object.keys(tokensBefore).length
- expect(numberOfTokens).toBe(1)
+ expect(numberOfTokens).toStrictEqual(1)
const address = await container.call('getnewaddress')
const metadata = {
@@ -150,31 +150,31 @@ describe('masternode', () => {
}
const data = await client.token.createToken(metadata)
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
await container.generate(1)
numberOfTokens += 1
const tokensAfter = await client.token.listTokens()
- expect(Object.keys(tokensAfter).length).toBe(numberOfTokens)
+ expect(Object.keys(tokensAfter).length).toStrictEqual(numberOfTokens)
for (const k in tokensAfter) {
if (tokensAfter[k].symbol === metadata.symbol) {
const newToken = tokensAfter[k]
- expect(newToken.symbolKey).toBe(`${metadata.symbol}#${k}`)
- expect(newToken.name).toBe(metadata.name)
- expect(newToken.mintable).toBe(metadata.mintable)
- expect(newToken.tradeable).toBe(metadata.tradeable)
- expect(newToken.collateralAddress).toBe(metadata.collateralAddress)
- expect(newToken.isDAT).toBe(metadata.isDAT)
- expect(newToken.decimal).toBe(8)
- expect(newToken.limit).toBe(0)
- expect(newToken.isLPS).toBe(false)
- expect(newToken.finalized).toBe(false)
- expect(newToken.minted).toBe(0)
- expect(typeof newToken.creationTx).toBe('string')
- expect(typeof newToken.destructionTx).toBe('string')
- expect(typeof newToken.creationHeight).toBe('number')
- expect(typeof newToken.destructionHeight).toBe('number')
+ expect(newToken.symbolKey).toStrictEqual(`${metadata.symbol}#${k}`)
+ expect(newToken.name).toStrictEqual(metadata.name)
+ expect(newToken.mintable).toStrictEqual(metadata.mintable)
+ expect(newToken.tradeable).toStrictEqual(metadata.tradeable)
+ expect(newToken.collateralAddress).toStrictEqual(metadata.collateralAddress)
+ expect(newToken.isDAT).toStrictEqual(metadata.isDAT)
+ expect(newToken.decimal).toStrictEqual(8)
+ expect(newToken.limit).toStrictEqual(0)
+ expect(newToken.isLPS).toStrictEqual(false)
+ expect(newToken.finalized).toStrictEqual(false)
+ expect(newToken.minted).toStrictEqual(0)
+ expect(typeof newToken.creationTx).toStrictEqual('string')
+ expect(typeof newToken.destructionTx).toStrictEqual('string')
+ expect(typeof newToken.creationHeight).toStrictEqual('number')
+ expect(typeof newToken.destructionHeight).toStrictEqual('number')
}
}
})
@@ -199,35 +199,35 @@ describe('masternode', () => {
txid: utxos[0].txid,
vout: utxos[0].vout
}])
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
await container.generate(1)
numberOfTokens += 1
await waitForExpect(async () => {
const tokensAfter = await client.token.listTokens()
- expect(Object.keys(tokensAfter).length).toBe(numberOfTokens)
+ expect(Object.keys(tokensAfter).length).toStrictEqual(numberOfTokens)
})
const tokensAfter = await client.token.listTokens()
for (const k in tokensAfter) {
if (tokensAfter[k].symbol === metadata.symbol) {
const newToken = tokensAfter[k]
- expect(newToken.symbolKey).toBe(`${metadata.symbol}#${k}`)
- expect(newToken.name).toBe(metadata.name)
- expect(newToken.mintable).toBe(metadata.mintable)
- expect(newToken.tradeable).toBe(metadata.tradeable)
- expect(newToken.collateralAddress).toBe(metadata.collateralAddress)
- expect(newToken.isDAT).toBe(metadata.isDAT)
- expect(newToken.decimal).toBe(8)
- expect(newToken.limit).toBe(0)
- expect(newToken.isLPS).toBe(false)
- expect(newToken.finalized).toBe(false)
- expect(newToken.minted).toBe(0)
- expect(typeof newToken.creationTx).toBe('string')
- expect(typeof newToken.destructionTx).toBe('string')
- expect(typeof newToken.creationHeight).toBe('number')
- expect(typeof newToken.destructionHeight).toBe('number')
+ expect(newToken.symbolKey).toStrictEqual(`${metadata.symbol}#${k}`)
+ expect(newToken.name).toStrictEqual(metadata.name)
+ expect(newToken.mintable).toStrictEqual(metadata.mintable)
+ expect(newToken.tradeable).toStrictEqual(metadata.tradeable)
+ expect(newToken.collateralAddress).toStrictEqual(metadata.collateralAddress)
+ expect(newToken.isDAT).toStrictEqual(metadata.isDAT)
+ expect(newToken.decimal).toStrictEqual(8)
+ expect(newToken.limit).toStrictEqual(0)
+ expect(newToken.isLPS).toStrictEqual(false)
+ expect(newToken.finalized).toStrictEqual(false)
+ expect(newToken.minted).toStrictEqual(0)
+ expect(typeof newToken.creationTx).toStrictEqual('string')
+ expect(typeof newToken.destructionTx).toStrictEqual('string')
+ expect(typeof newToken.creationHeight).toStrictEqual('number')
+ expect(typeof newToken.destructionHeight).toStrictEqual('number')
}
}
})
@@ -243,7 +243,7 @@ describe('masternode', () => {
collateralAddress: address
}
const data = await client.token.createToken(metadata)
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
await container.generate(1)
@@ -275,13 +275,13 @@ describe('masternode', () => {
it('should updateToken', async () => {
const { [tokenDTESTId]: tokenBefore } = await client.token.getToken(`DTEST#${tokenDTESTId}`)
- expect(tokenBefore.symbol).toBe('DTEST')
- expect(tokenBefore.name).toBe('DTEST')
- expect(tokenBefore.isDAT).toBe(false)
- expect(tokenBefore.mintable).toBe(true)
- expect(tokenBefore.tradeable).toBe(true)
- expect(tokenBefore.finalized).toBe(false)
- expect(tokenBefore.symbolKey).toBe(`DTEST#${tokenDTESTId}`)
+ expect(tokenBefore.symbol).toStrictEqual('DTEST')
+ expect(tokenBefore.name).toStrictEqual('DTEST')
+ expect(tokenBefore.isDAT).toStrictEqual(false)
+ expect(tokenBefore.mintable).toStrictEqual(true)
+ expect(tokenBefore.tradeable).toStrictEqual(true)
+ expect(tokenBefore.finalized).toStrictEqual(false)
+ expect(tokenBefore.symbolKey).toStrictEqual(`DTEST#${tokenDTESTId}`)
const data = await client.token.updateToken(`DTEST#${tokenDTESTId}`, {
symbol: 'DDEST',
@@ -291,41 +291,41 @@ describe('masternode', () => {
tradeable: false,
finalize: false
})
- expect(typeof data).toBe('string')
+ expect(typeof data).toStrictEqual('string')
await container.generate(1)
const { [tokenDTESTId]: tokenAfter } = await client.token.getToken('DDEST')
- expect(tokenAfter.symbol).toBe('DDEST')
- expect(tokenAfter.name).toBe('DDEST')
- expect(tokenAfter.isDAT).toBe(true)
- expect(tokenAfter.mintable).toBe(false)
- expect(tokenAfter.tradeable).toBe(false)
- expect(tokenAfter.finalized).toBe(false)
+ expect(tokenAfter.symbol).toStrictEqual('DDEST')
+ expect(tokenAfter.name).toStrictEqual('DDEST')
+ expect(tokenAfter.isDAT).toStrictEqual(true)
+ expect(tokenAfter.mintable).toStrictEqual(false)
+ expect(tokenAfter.tradeable).toStrictEqual(false)
+ expect(tokenAfter.finalized).toStrictEqual(false)
// NOTE(canonbrother): isDAT will not show the ID
- expect(tokenAfter.symbolKey).toBe('DDEST')
+ expect(tokenAfter.symbolKey).toStrictEqual('DDEST')
})
it('should updateToken by token id', async () => {
const { [tokenDABCId]: tokenBefore } = await client.token.getToken(`DABC#${tokenDABCId}`)
- expect(tokenBefore.mintable).toBe(true)
+ expect(tokenBefore.mintable).toStrictEqual(true)
await client.token.updateToken(tokenDABCId, { mintable: false })
await container.generate(1)
const { [tokenDABCId]: tokenAfter } = await client.token.getToken(`DABC#${tokenDABCId}`)
- expect(tokenAfter.mintable).toBe(false)
+ expect(tokenAfter.mintable).toStrictEqual(false)
})
it('should updateToken by creationTx', async () => {
const { [tokenDABCId]: tokenBefore } = await client.token.getToken(`DABC#${tokenDABCId}`)
- expect(tokenBefore.tradeable).toBe(true)
+ expect(tokenBefore.tradeable).toStrictEqual(true)
const { creationTx } = tokenBefore
await client.token.updateToken(creationTx, { tradeable: false })
await container.generate(1)
const { [tokenDABCId]: tokenAfter } = await client.token.getToken(`DABC#${tokenDABCId}`)
- expect(tokenAfter.tradeable).toBe(false)
+ expect(tokenAfter.tradeable).toStrictEqual(false)
})
})
@@ -346,53 +346,53 @@ describe('masternode', () => {
const tokens = await client.token.listTokens()
for (const k in tokens) {
const token = tokens[k]
- expect(token.decimal).toBe(8)
- expect(token.limit).toBe(0)
- expect(token.minted).toBe(0)
- expect(token.isLPS).toBe(false)
- expect(typeof token.creationTx).toBe('string')
- expect(typeof token.creationHeight).toBe('number')
- expect(typeof token.destructionTx).toBe('string')
- expect(typeof token.destructionHeight).toBe('number')
- expect(typeof token.collateralAddress).toBe('string')
+ expect(token.decimal).toStrictEqual(8)
+ expect(token.limit).toStrictEqual(0)
+ expect(token.minted).toStrictEqual(0)
+ expect(token.isLPS).toStrictEqual(false)
+ expect(typeof token.creationTx).toStrictEqual('string')
+ expect(typeof token.creationHeight).toStrictEqual('number')
+ expect(typeof token.destructionTx).toStrictEqual('string')
+ expect(typeof token.destructionHeight).toStrictEqual('number')
+ expect(typeof token.collateralAddress).toStrictEqual('string')
switch (token.symbol) {
case 'DFI':
- expect(token.symbol).toBe('DFI')
- expect(token.symbolKey).toBe('DFI')
- expect(token.name).toBe('Default Defi token')
- expect(token.mintable).toBe(false)
- expect(token.tradeable).toBe(true)
- expect(token.isDAT).toBe(true)
- expect(token.finalized).toBe(true)
- expect(token.collateralAddress).toBe('')
+ expect(token.symbol).toStrictEqual('DFI')
+ expect(token.symbolKey).toStrictEqual('DFI')
+ expect(token.name).toStrictEqual('Default Defi token')
+ expect(token.mintable).toStrictEqual(false)
+ expect(token.tradeable).toStrictEqual(true)
+ expect(token.isDAT).toStrictEqual(true)
+ expect(token.finalized).toStrictEqual(true)
+ expect(token.collateralAddress).toStrictEqual('')
break
case 'DBTC':
- expect(token.symbol).toBe('DBTC')
- expect(token.symbolKey).toBe('DBTC')
- expect(token.name).toBe('DBTC')
- expect(token.mintable).toBe(true)
- expect(token.tradeable).toBe(true)
- expect(token.isDAT).toBe(true)
- expect(token.finalized).toBe(false)
+ expect(token.symbol).toStrictEqual('DBTC')
+ expect(token.symbolKey).toStrictEqual('DBTC')
+ expect(token.name).toStrictEqual('DBTC')
+ expect(token.mintable).toStrictEqual(true)
+ expect(token.tradeable).toStrictEqual(true)
+ expect(token.isDAT).toStrictEqual(true)
+ expect(token.finalized).toStrictEqual(false)
break
case 'DNOTMINT':
- expect(token.symbol).toBe('DNOTMINT')
- expect(token.symbolKey).toBe(`DNOTMINT#${k}`)
- expect(token.name).toBe('DNOTMINT')
- expect(token.mintable).toBe(false)
- expect(token.tradeable).toBe(true)
- expect(token.isDAT).toBe(false)
- expect(token.finalized).toBe(false)
+ expect(token.symbol).toStrictEqual('DNOTMINT')
+ expect(token.symbolKey).toStrictEqual(`DNOTMINT#${k}`)
+ expect(token.name).toStrictEqual('DNOTMINT')
+ expect(token.mintable).toStrictEqual(false)
+ expect(token.tradeable).toStrictEqual(true)
+ expect(token.isDAT).toStrictEqual(false)
+ expect(token.finalized).toStrictEqual(false)
break
case 'DNOTTRAD':
- expect(token.symbol).toBe('DNOTTRAD')
- expect(token.symbolKey).toBe(`DNOTTRAD#${k}`)
- expect(token.name).toBe('DNOTTRAD')
- expect(token.mintable).toBe(true)
- expect(token.tradeable).toBe(false)
- expect(token.isDAT).toBe(false)
- expect(token.finalized).toBe(false)
+ expect(token.symbol).toStrictEqual('DNOTTRAD')
+ expect(token.symbolKey).toStrictEqual(`DNOTTRAD#${k}`)
+ expect(token.name).toStrictEqual('DNOTTRAD')
+ expect(token.mintable).toStrictEqual(true)
+ expect(token.tradeable).toStrictEqual(false)
+ expect(token.isDAT).toStrictEqual(false)
+ expect(token.finalized).toStrictEqual(false)
break
}
}
@@ -406,7 +406,7 @@ describe('masternode', () => {
}
const tokens = await client.token.listTokens(pagination)
- expect(Object.keys(tokens).length).toBe(0)
+ expect(Object.keys(tokens).length).toStrictEqual(0)
})
it('should listTokens with pagination limit', async () => {
@@ -417,7 +417,7 @@ describe('masternode', () => {
}
const tokens = await client.token.listTokens(pagination)
- expect(Object.keys(tokens).length).toBe(2)
+ expect(Object.keys(tokens).length).toStrictEqual(2)
})
it('should listTokens with verbose false', async () => {
@@ -435,9 +435,9 @@ describe('masternode', () => {
const token = await client.token.listTokens(pagination, false)
const data = token['0']
- expect(data.symbol).toBe('DFI')
- expect(data.symbolKey).toBe('DFI')
- expect(data.name).toBe('Default Defi token')
+ expect(data.symbol).toStrictEqual('DFI')
+ expect(data.symbolKey).toStrictEqual('DFI')
+ expect(data.name).toStrictEqual('Default Defi token')
})
})
@@ -451,22 +451,22 @@ describe('masternode', () => {
const token = await client.token.getToken('DFI')
const data = token['0']
- expect(data.symbol).toBe('DFI')
- expect(data.symbolKey).toBe('DFI')
- expect(data.name).toBe('Default Defi token')
- expect(data.decimal).toBe(8)
- expect(data.limit).toBe(0)
- expect(data.mintable).toBe(false)
- expect(data.tradeable).toBe(true)
- expect(data.isDAT).toBe(true)
- expect(data.isLPS).toBe(false)
- expect(data.finalized).toBe(true)
- expect(data.minted).toBe(0)
- expect(data.creationTx).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(data.creationHeight).toBe(0)
- expect(data.destructionTx).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(data.destructionHeight).toBe(-1)
- expect(data.collateralAddress).toBe('')
+ expect(data.symbol).toStrictEqual('DFI')
+ expect(data.symbolKey).toStrictEqual('DFI')
+ expect(data.name).toStrictEqual('Default Defi token')
+ expect(data.decimal).toStrictEqual(8)
+ expect(data.limit).toStrictEqual(0)
+ expect(data.mintable).toStrictEqual(false)
+ expect(data.tradeable).toStrictEqual(true)
+ expect(data.isDAT).toStrictEqual(true)
+ expect(data.isLPS).toStrictEqual(false)
+ expect(data.finalized).toStrictEqual(true)
+ expect(data.minted).toStrictEqual(0)
+ expect(data.creationTx).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(data.creationHeight).toStrictEqual(0)
+ expect(data.destructionTx).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(data.destructionHeight).toStrictEqual(-1)
+ expect(data.collateralAddress).toStrictEqual('')
})
})
})
diff --git a/packages/jellyfish-api-core/__tests__/category/wallet.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet.test.ts
index e505330f7b..f91139a5c7 100644
--- a/packages/jellyfish-api-core/__tests__/category/wallet.test.ts
+++ b/packages/jellyfish-api-core/__tests__/category/wallet.test.ts
@@ -21,7 +21,7 @@ describe('non masternode', () => {
it('should getBalance = 0', async () => {
const balance: BigNumber = await client.wallet.getBalance()
- expect(balance.toString()).toBe('0')
+ expect(balance.toString()).toStrictEqual('0')
})
})
@@ -30,7 +30,7 @@ describe('non masternode', () => {
return await waitForExpect(async () => {
const address = await client.wallet.getNewAddress()
- expect(typeof address).toBe('string')
+ expect(typeof address).toStrictEqual('string')
})
})
@@ -38,7 +38,7 @@ describe('non masternode', () => {
return await waitForExpect(async () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
- expect(typeof aliceAddress).toBe('string')
+ expect(typeof aliceAddress).toStrictEqual('string')
})
})
@@ -53,26 +53,26 @@ describe('non masternode', () => {
const bech32Address = await client.wallet.getNewAddress('bob', wallet.AddressType.BECH32)
const bech32AddressValidateResult = await client.wallet.validateAddress(bech32Address)
- expect(typeof legacyAddress).toBe('string')
- expect(legacyAddressValidateResult.isvalid).toBe(true)
- expect(legacyAddressValidateResult.address).toBe(legacyAddress)
- expect(typeof legacyAddressValidateResult.scriptPubKey).toBe('string')
- expect(legacyAddressValidateResult.isscript).toBe(false)
- expect(legacyAddressValidateResult.iswitness).toBe(false)
+ expect(typeof legacyAddress).toStrictEqual('string')
+ expect(legacyAddressValidateResult.isvalid).toStrictEqual(true)
+ expect(legacyAddressValidateResult.address).toStrictEqual(legacyAddress)
+ expect(typeof legacyAddressValidateResult.scriptPubKey).toStrictEqual('string')
+ expect(legacyAddressValidateResult.isscript).toStrictEqual(false)
+ expect(legacyAddressValidateResult.iswitness).toStrictEqual(false)
- expect(typeof p2shSegwitAddress).toBe('string')
- expect(p2shSegwitAddressValidateResult.isvalid).toBe(true)
- expect(p2shSegwitAddressValidateResult.address).toBe(p2shSegwitAddress)
- expect(typeof p2shSegwitAddressValidateResult.scriptPubKey).toBe('string')
- expect(p2shSegwitAddressValidateResult.isscript).toBe(true)
- expect(p2shSegwitAddressValidateResult.iswitness).toBe(false)
+ expect(typeof p2shSegwitAddress).toStrictEqual('string')
+ expect(p2shSegwitAddressValidateResult.isvalid).toStrictEqual(true)
+ expect(p2shSegwitAddressValidateResult.address).toStrictEqual(p2shSegwitAddress)
+ expect(typeof p2shSegwitAddressValidateResult.scriptPubKey).toStrictEqual('string')
+ expect(p2shSegwitAddressValidateResult.isscript).toStrictEqual(true)
+ expect(p2shSegwitAddressValidateResult.iswitness).toStrictEqual(false)
- expect(typeof bech32Address).toBe('string')
- expect(bech32AddressValidateResult.isvalid).toBe(true)
- expect(bech32AddressValidateResult.address).toBe(bech32Address)
- expect(typeof bech32AddressValidateResult.scriptPubKey).toBe('string')
- expect(bech32AddressValidateResult.isscript).toBe(false)
- expect(bech32AddressValidateResult.iswitness).toBe(true)
+ expect(typeof bech32Address).toStrictEqual('string')
+ expect(bech32AddressValidateResult.isvalid).toStrictEqual(true)
+ expect(bech32AddressValidateResult.address).toStrictEqual(bech32Address)
+ expect(typeof bech32AddressValidateResult.scriptPubKey).toStrictEqual('string')
+ expect(bech32AddressValidateResult.isscript).toStrictEqual(false)
+ expect(bech32AddressValidateResult.iswitness).toStrictEqual(true)
})
})
})
@@ -83,23 +83,23 @@ describe('non masternode', () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const addressInfo: wallet.AddressInfo = await client.wallet.getAddressInfo(aliceAddress)
- expect(addressInfo.address).toBe(aliceAddress)
- expect(typeof addressInfo.scriptPubKey).toBe('string')
- expect(addressInfo.ismine).toBe(true)
- expect(addressInfo.solvable).toBe(true)
- expect(typeof addressInfo.desc).toBe('string')
- expect(addressInfo.iswatchonly).toBe(false)
- expect(addressInfo.isscript).toBe(false)
- expect(addressInfo.iswitness).toBe(true)
- expect(typeof addressInfo.pubkey).toBe('string')
- expect(addressInfo.label).toBe('alice')
- expect(addressInfo.ischange).toBe(false)
- expect(typeof addressInfo.timestamp).toBe('number')
- expect(typeof addressInfo.hdkeypath).toBe('string')
- expect(typeof addressInfo.hdseedid).toBe('string')
+ expect(addressInfo.address).toStrictEqual(aliceAddress)
+ expect(typeof addressInfo.scriptPubKey).toStrictEqual('string')
+ expect(addressInfo.ismine).toStrictEqual(true)
+ expect(addressInfo.solvable).toStrictEqual(true)
+ expect(typeof addressInfo.desc).toStrictEqual('string')
+ expect(addressInfo.iswatchonly).toStrictEqual(false)
+ expect(addressInfo.isscript).toStrictEqual(false)
+ expect(addressInfo.iswitness).toStrictEqual(true)
+ expect(typeof addressInfo.pubkey).toStrictEqual('string')
+ expect(addressInfo.label).toStrictEqual('alice')
+ expect(addressInfo.ischange).toStrictEqual(false)
+ expect(typeof addressInfo.timestamp).toStrictEqual('number')
+ expect(typeof addressInfo.hdkeypath).toStrictEqual('string')
+ expect(typeof addressInfo.hdseedid).toStrictEqual('string')
expect(addressInfo.labels.length).toBeGreaterThanOrEqual(1)
- expect(addressInfo.labels[0].name).toBe('alice')
- expect(addressInfo.labels[0].purpose).toBe('receive')
+ expect(addressInfo.labels[0].name).toStrictEqual('alice')
+ expect(addressInfo.labels[0].purpose).toStrictEqual('receive')
})
})
})
@@ -110,11 +110,11 @@ describe('non masternode', () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const result: wallet.ValidateAddressResult = await client.wallet.validateAddress(aliceAddress)
- expect(result.isvalid).toBe(true)
- expect(result.address).toBe(aliceAddress)
- expect(typeof result.scriptPubKey).toBe('string')
- expect(result.isscript).toBe(false)
- expect(result.iswitness).toBe(true)
+ expect(result.isvalid).toStrictEqual(true)
+ expect(result.address).toStrictEqual(aliceAddress)
+ expect(typeof result.scriptPubKey).toStrictEqual('string')
+ expect(result.isscript).toStrictEqual(false)
+ expect(result.iswitness).toStrictEqual(true)
})
})
})
@@ -124,7 +124,7 @@ describe('non masternode', () => {
return await waitForExpect(async () => {
const data = await client.wallet.listAddressGroupings()
- expect(data.length === 0).toBe(true)
+ expect(data.length === 0).toStrictEqual(true)
})
})
})
@@ -134,24 +134,24 @@ describe('non masternode', () => {
return await waitForExpect(async () => {
const walletInfo = await client.wallet.getWalletInfo()
- expect(walletInfo.walletname).toBe('')
- expect(walletInfo.walletversion).toBe(169900)
- expect(walletInfo.balance instanceof BigNumber).toBe(true)
- expect(walletInfo.balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(walletInfo.unconfirmed_balance instanceof BigNumber).toBe(true)
- expect(walletInfo.unconfirmed_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(walletInfo.immature_balance instanceof BigNumber).toBe(true)
- expect(walletInfo.immature_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
+ expect(walletInfo.walletname).toStrictEqual('')
+ expect(walletInfo.walletversion).toStrictEqual(169900)
+ expect(walletInfo.balance instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(walletInfo.unconfirmed_balance instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.unconfirmed_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(walletInfo.immature_balance instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.immature_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
expect(walletInfo.txcount).toBeGreaterThanOrEqual(0)
- expect(typeof walletInfo.keypoololdest).toBe('number')
- expect(typeof walletInfo.keypoolsize).toBe('number')
- expect(typeof walletInfo.keypoolsize_hd_internal).toBe('number')
- expect(walletInfo.paytxfee instanceof BigNumber).toBe(true)
- expect(walletInfo.paytxfee.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(typeof walletInfo.hdseedid).toBe('string')
- expect(walletInfo.private_keys_enabled).toBe(true)
- expect(walletInfo.avoid_reuse).toBe(false)
- expect(walletInfo.scanning).toBe(false)
+ expect(typeof walletInfo.keypoololdest).toStrictEqual('number')
+ expect(typeof walletInfo.keypoolsize).toStrictEqual('number')
+ expect(typeof walletInfo.keypoolsize_hd_internal).toStrictEqual('number')
+ expect(walletInfo.paytxfee instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.paytxfee.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(typeof walletInfo.hdseedid).toStrictEqual('string')
+ expect(walletInfo.private_keys_enabled).toStrictEqual(true)
+ expect(walletInfo.avoid_reuse).toStrictEqual(false)
+ expect(walletInfo.scanning).toStrictEqual(false)
})
})
})
@@ -160,15 +160,15 @@ describe('non masternode', () => {
it('should setWalletFlag', async () => {
return await waitForExpect(async () => {
const walletInfoBefore = await client.wallet.getWalletInfo()
- expect(walletInfoBefore.avoid_reuse).toBe(false)
+ expect(walletInfoBefore.avoid_reuse).toStrictEqual(false)
const result = await client.wallet.setWalletFlag(WalletFlag.AVOID_REUSE)
- expect(result.flag_name).toBe('avoid_reuse')
- expect(result.flag_state).toBe(true)
- expect(result.warnings).toBe('You need to rescan the blockchain in order to correctly mark used destinations in the past. Until this is done, some destinations may be considered unused, even if the opposite is the case.')
+ expect(result.flag_name).toStrictEqual('avoid_reuse')
+ expect(result.flag_state).toStrictEqual(true)
+ expect(result.warnings).toStrictEqual('You need to rescan the blockchain in order to correctly mark used destinations in the past. Until this is done, some destinations may be considered unused, even if the opposite is the case.')
const walletInfoAfter = await client.wallet.getWalletInfo()
- expect(walletInfoAfter.avoid_reuse).toBe(true)
+ expect(walletInfoAfter.avoid_reuse).toStrictEqual(true)
})
})
})
@@ -178,8 +178,8 @@ describe('non masternode', () => {
return await waitForExpect(async () => {
const wallet = await client.wallet.createWallet('alice')
- expect(wallet.name).toBe('alice')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('alice')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
@@ -187,8 +187,8 @@ describe('non masternode', () => {
return await waitForExpect(async () => {
const wallet = await client.wallet.createWallet('bob', true)
- expect(wallet.name).toBe('bob')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('bob')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
@@ -197,8 +197,8 @@ describe('non masternode', () => {
const options = { blank: true }
const wallet = await client.wallet.createWallet('charlie', false, options)
- expect(wallet.name).toBe('charlie')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('charlie')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
@@ -207,8 +207,8 @@ describe('non masternode', () => {
const options = { passphrase: 'shhh...' }
const wallet = await client.wallet.createWallet('david', false, options)
- expect(wallet.name).toBe('david')
- expect(wallet.warning).toBe('')
+ expect(wallet.name).toStrictEqual('david')
+ expect(wallet.warning).toStrictEqual('')
})
})
@@ -217,8 +217,8 @@ describe('non masternode', () => {
const options = { avoidReuse: true }
const wallet = await client.wallet.createWallet('eve', false, options)
- expect(wallet.name).toBe('eve')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('eve')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
})
@@ -242,7 +242,7 @@ describe('masternode', () => {
it('should getBalance >= 100', async () => {
return await waitForExpect(async () => {
const balance: BigNumber = await client.wallet.getBalance()
- expect(balance.isGreaterThan(new BigNumber('100'))).toBe(true)
+ expect(balance.isGreaterThan(new BigNumber('100'))).toStrictEqual(true)
})
})
})
@@ -254,18 +254,18 @@ describe('masternode', () => {
expect(utxos.length).toBeGreaterThan(0)
for (let i = 0; i < utxos.length; i += 1) {
const utxo = utxos[i]
- expect(typeof utxo.txid).toBe('string')
- expect(typeof utxo.vout).toBe('number')
- expect(typeof utxo.address).toBe('string')
- expect(typeof utxo.label).toBe('string')
- expect(typeof utxo.scriptPubKey).toBe('string')
- expect(utxo.amount instanceof BigNumber).toBe(true)
- expect(typeof utxo.tokenId).toBe('string')
- expect(typeof utxo.confirmations).toBe('number')
- expect(typeof utxo.spendable).toBe('boolean')
- expect(typeof utxo.solvable).toBe('boolean')
- expect(typeof utxo.desc).toBe('string')
- expect(typeof utxo.safe).toBe('boolean')
+ expect(typeof utxo.txid).toStrictEqual('string')
+ expect(typeof utxo.vout).toStrictEqual('number')
+ expect(typeof utxo.address).toStrictEqual('string')
+ expect(typeof utxo.label).toStrictEqual('string')
+ expect(typeof utxo.scriptPubKey).toStrictEqual('string')
+ expect(utxo.amount instanceof BigNumber).toStrictEqual(true)
+ expect(typeof utxo.tokenId).toStrictEqual('string')
+ expect(typeof utxo.confirmations).toStrictEqual('number')
+ expect(typeof utxo.spendable).toStrictEqual('boolean')
+ expect(typeof utxo.solvable).toStrictEqual('boolean')
+ expect(typeof utxo.desc).toStrictEqual('string')
+ expect(typeof utxo.safe).toStrictEqual('boolean')
}
})
})
@@ -295,7 +295,7 @@ describe('masternode', () => {
await waitForExpect(async () => {
const utxos: UTXO[] = await client.wallet.listUnspent(1, 9999999, options)
utxos.forEach(utxo => {
- expect(utxo.address).toBe('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
+ expect(utxo.address).toStrictEqual('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
})
})
})
@@ -305,7 +305,7 @@ describe('masternode', () => {
await waitForExpect(async () => {
const utxos: UTXO[] = await client.wallet.listUnspent(1, 9999999, options)
utxos.forEach(utxo => {
- expect(utxo.safe).toBe(true)
+ expect(utxo.safe).toStrictEqual(true)
})
})
})
@@ -315,7 +315,7 @@ describe('masternode', () => {
await waitForExpect(async () => {
const utxos: UTXO[] = await client.wallet.listUnspent(1, 9999999, options)
utxos.forEach(utxo => {
- expect(utxo.amount.isGreaterThanOrEqualTo(new BigNumber('5'))).toBe(true)
+ expect(utxo.amount.isGreaterThanOrEqualTo(new BigNumber('5'))).toStrictEqual(true)
})
})
})
@@ -325,7 +325,7 @@ describe('masternode', () => {
await waitForExpect(async () => {
const utxos: UTXO[] = await client.wallet.listUnspent(1, 9999999, options)
utxos.forEach(utxo => {
- expect(utxo.amount.isLessThanOrEqualTo(new BigNumber('100'))).toBe(true)
+ expect(utxo.amount.isLessThanOrEqualTo(new BigNumber('100'))).toStrictEqual(true)
})
})
})
@@ -343,7 +343,7 @@ describe('masternode', () => {
await waitForExpect(async () => {
const utxos: UTXO[] = await client.wallet.listUnspent(1, 9999999, options)
const sum: BigNumber = utxos.map(utxo => utxo.amount).reduce((acc, val) => acc.plus(val))
- expect(sum.isGreaterThanOrEqualTo(new BigNumber('100'))).toBe(true)
+ expect(sum.isGreaterThanOrEqualTo(new BigNumber('100'))).toStrictEqual(true)
})
})
@@ -352,7 +352,7 @@ describe('masternode', () => {
await waitForExpect(async () => {
const utxos: UTXO[] = await client.wallet.listUnspent(1, 9999999, options)
utxos.forEach(utxo => {
- expect(utxo.tokenId).toBe('0')
+ expect(utxo.tokenId).toStrictEqual('0')
})
})
})
@@ -363,7 +363,7 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const address = await client.wallet.getNewAddress()
- expect(typeof address).toBe('string')
+ expect(typeof address).toStrictEqual('string')
})
})
@@ -371,7 +371,7 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
- expect(typeof aliceAddress).toBe('string')
+ expect(typeof aliceAddress).toStrictEqual('string')
})
})
@@ -386,26 +386,26 @@ describe('masternode', () => {
const bech32Address = await client.wallet.getNewAddress('bob', wallet.AddressType.BECH32)
const bech32AddressValidateResult = await client.wallet.validateAddress(bech32Address)
- expect(typeof legacyAddress).toBe('string')
- expect(legacyAddressValidateResult.isvalid).toBe(true)
- expect(legacyAddressValidateResult.address).toBe(legacyAddress)
- expect(typeof legacyAddressValidateResult.scriptPubKey).toBe('string')
- expect(legacyAddressValidateResult.isscript).toBe(false)
- expect(legacyAddressValidateResult.iswitness).toBe(false)
+ expect(typeof legacyAddress).toStrictEqual('string')
+ expect(legacyAddressValidateResult.isvalid).toStrictEqual(true)
+ expect(legacyAddressValidateResult.address).toStrictEqual(legacyAddress)
+ expect(typeof legacyAddressValidateResult.scriptPubKey).toStrictEqual('string')
+ expect(legacyAddressValidateResult.isscript).toStrictEqual(false)
+ expect(legacyAddressValidateResult.iswitness).toStrictEqual(false)
- expect(typeof p2shSegwitAddress).toBe('string')
- expect(p2shSegwitAddressValidateResult.isvalid).toBe(true)
- expect(p2shSegwitAddressValidateResult.address).toBe(p2shSegwitAddress)
- expect(typeof p2shSegwitAddressValidateResult.scriptPubKey).toBe('string')
- expect(p2shSegwitAddressValidateResult.isscript).toBe(true)
- expect(p2shSegwitAddressValidateResult.iswitness).toBe(false)
+ expect(typeof p2shSegwitAddress).toStrictEqual('string')
+ expect(p2shSegwitAddressValidateResult.isvalid).toStrictEqual(true)
+ expect(p2shSegwitAddressValidateResult.address).toStrictEqual(p2shSegwitAddress)
+ expect(typeof p2shSegwitAddressValidateResult.scriptPubKey).toStrictEqual('string')
+ expect(p2shSegwitAddressValidateResult.isscript).toStrictEqual(true)
+ expect(p2shSegwitAddressValidateResult.iswitness).toStrictEqual(false)
- expect(typeof bech32Address).toBe('string')
- expect(bech32AddressValidateResult.isvalid).toBe(true)
- expect(bech32AddressValidateResult.address).toBe(bech32Address)
- expect(typeof bech32AddressValidateResult.scriptPubKey).toBe('string')
- expect(bech32AddressValidateResult.isscript).toBe(false)
- expect(bech32AddressValidateResult.iswitness).toBe(true)
+ expect(typeof bech32Address).toStrictEqual('string')
+ expect(bech32AddressValidateResult.isvalid).toStrictEqual(true)
+ expect(bech32AddressValidateResult.address).toStrictEqual(bech32Address)
+ expect(typeof bech32AddressValidateResult.scriptPubKey).toStrictEqual('string')
+ expect(bech32AddressValidateResult.isscript).toStrictEqual(false)
+ expect(bech32AddressValidateResult.iswitness).toStrictEqual(true)
})
})
})
@@ -416,23 +416,23 @@ describe('masternode', () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const addressInfo: wallet.AddressInfo = await client.wallet.getAddressInfo(aliceAddress)
- expect(addressInfo.address).toBe(aliceAddress)
- expect(typeof addressInfo.scriptPubKey).toBe('string')
- expect(addressInfo.ismine).toBe(true)
- expect(addressInfo.solvable).toBe(true)
- expect(typeof addressInfo.desc).toBe('string')
- expect(addressInfo.iswatchonly).toBe(false)
- expect(addressInfo.isscript).toBe(false)
- expect(addressInfo.iswitness).toBe(true)
- expect(typeof addressInfo.pubkey).toBe('string')
- expect(addressInfo.label).toBe('alice')
- expect(addressInfo.ischange).toBe(false)
- expect(typeof addressInfo.timestamp).toBe('number')
- expect(typeof addressInfo.hdkeypath).toBe('string')
- expect(typeof addressInfo.hdseedid).toBe('string')
+ expect(addressInfo.address).toStrictEqual(aliceAddress)
+ expect(typeof addressInfo.scriptPubKey).toStrictEqual('string')
+ expect(addressInfo.ismine).toStrictEqual(true)
+ expect(addressInfo.solvable).toStrictEqual(true)
+ expect(typeof addressInfo.desc).toStrictEqual('string')
+ expect(addressInfo.iswatchonly).toStrictEqual(false)
+ expect(addressInfo.isscript).toStrictEqual(false)
+ expect(addressInfo.iswitness).toStrictEqual(true)
+ expect(typeof addressInfo.pubkey).toStrictEqual('string')
+ expect(addressInfo.label).toStrictEqual('alice')
+ expect(addressInfo.ischange).toStrictEqual(false)
+ expect(typeof addressInfo.timestamp).toStrictEqual('number')
+ expect(typeof addressInfo.hdkeypath).toStrictEqual('string')
+ expect(typeof addressInfo.hdseedid).toStrictEqual('string')
expect(addressInfo.labels.length).toBeGreaterThanOrEqual(1)
- expect(addressInfo.labels[0].name).toBe('alice')
- expect(addressInfo.labels[0].purpose).toBe('receive')
+ expect(addressInfo.labels[0].name).toStrictEqual('alice')
+ expect(addressInfo.labels[0].purpose).toStrictEqual('receive')
})
})
})
@@ -443,11 +443,11 @@ describe('masternode', () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const result: wallet.ValidateAddressResult = await client.wallet.validateAddress(aliceAddress)
- expect(result.isvalid).toBe(true)
- expect(result.address).toBe(aliceAddress)
- expect(typeof result.scriptPubKey).toBe('string')
- expect(result.isscript).toBe(false)
- expect(result.iswitness).toBe(true)
+ expect(result.isvalid).toStrictEqual(true)
+ expect(result.address).toStrictEqual(aliceAddress)
+ expect(typeof result.scriptPubKey).toStrictEqual('string')
+ expect(result.isscript).toStrictEqual(false)
+ expect(result.iswitness).toStrictEqual(true)
})
})
})
@@ -457,15 +457,15 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const data = await client.wallet.listAddressGroupings()
- expect(data[0][0][0]).toBe('mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy')
- expect(data[0][0][1] instanceof BigNumber).toBe(true)
- expect(data[0][0][1].isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(data[0][0][2]).toBe('coinbase')
+ expect(data[0][0][0]).toStrictEqual('mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy')
+ expect(data[0][0][1] instanceof BigNumber).toStrictEqual(true)
+ expect(data[0][0][1].isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(data[0][0][2]).toStrictEqual('coinbase')
- expect(data[1][0][0]).toBe('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
- expect(data[1][0][1] instanceof BigNumber).toBe(true)
- expect(data[1][0][1].isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(data[1][0][2]).toBe('coinbase')
+ expect(data[1][0][0]).toStrictEqual('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
+ expect(data[1][0][1] instanceof BigNumber).toStrictEqual(true)
+ expect(data[1][0][1].isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(data[1][0][2]).toStrictEqual('coinbase')
})
})
})
@@ -475,24 +475,24 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const walletInfo = await client.wallet.getWalletInfo()
- expect(walletInfo.walletname).toBe('')
- expect(walletInfo.walletversion).toBe(169900)
- expect(walletInfo.balance instanceof BigNumber).toBe(true)
- expect(walletInfo.balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(walletInfo.unconfirmed_balance instanceof BigNumber).toBe(true)
- expect(walletInfo.unconfirmed_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(walletInfo.immature_balance instanceof BigNumber).toBe(true)
- expect(walletInfo.immature_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
+ expect(walletInfo.walletname).toStrictEqual('')
+ expect(walletInfo.walletversion).toStrictEqual(169900)
+ expect(walletInfo.balance instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(walletInfo.unconfirmed_balance instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.unconfirmed_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(walletInfo.immature_balance instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.immature_balance.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
expect(walletInfo.txcount).toBeGreaterThanOrEqual(100)
- expect(typeof walletInfo.keypoololdest).toBe('number')
- expect(typeof walletInfo.keypoolsize).toBe('number')
- expect(typeof walletInfo.keypoolsize_hd_internal).toBe('number')
- expect(walletInfo.paytxfee instanceof BigNumber).toBe(true)
- expect(walletInfo.paytxfee.isGreaterThanOrEqualTo(new BigNumber('0'))).toBe(true)
- expect(typeof walletInfo.hdseedid).toBe('string')
- expect(walletInfo.private_keys_enabled).toBe(true)
- expect(walletInfo.avoid_reuse).toBe(false)
- expect(walletInfo.scanning).toBe(false)
+ expect(typeof walletInfo.keypoololdest).toStrictEqual('number')
+ expect(typeof walletInfo.keypoolsize).toStrictEqual('number')
+ expect(typeof walletInfo.keypoolsize_hd_internal).toStrictEqual('number')
+ expect(walletInfo.paytxfee instanceof BigNumber).toStrictEqual(true)
+ expect(walletInfo.paytxfee.isGreaterThanOrEqualTo(new BigNumber('0'))).toStrictEqual(true)
+ expect(typeof walletInfo.hdseedid).toStrictEqual('string')
+ expect(walletInfo.private_keys_enabled).toStrictEqual(true)
+ expect(walletInfo.avoid_reuse).toStrictEqual(false)
+ expect(walletInfo.scanning).toStrictEqual(false)
})
})
})
@@ -501,15 +501,15 @@ describe('masternode', () => {
it('should setWalletFlag', async () => {
return await waitForExpect(async () => {
const walletInfoBefore = await client.wallet.getWalletInfo()
- expect(walletInfoBefore.avoid_reuse).toBe(false)
+ expect(walletInfoBefore.avoid_reuse).toStrictEqual(false)
const result = await client.wallet.setWalletFlag(WalletFlag.AVOID_REUSE)
- expect(result.flag_name).toBe('avoid_reuse')
- expect(result.flag_state).toBe(true)
- expect(result.warnings).toBe('You need to rescan the blockchain in order to correctly mark used destinations in the past. Until this is done, some destinations may be considered unused, even if the opposite is the case.')
+ expect(result.flag_name).toStrictEqual('avoid_reuse')
+ expect(result.flag_state).toStrictEqual(true)
+ expect(result.warnings).toStrictEqual('You need to rescan the blockchain in order to correctly mark used destinations in the past. Until this is done, some destinations may be considered unused, even if the opposite is the case.')
const walletInfoAfter = await client.wallet.getWalletInfo()
- expect(walletInfoAfter.avoid_reuse).toBe(true)
+ expect(walletInfoAfter.avoid_reuse).toStrictEqual(true)
})
})
})
@@ -521,7 +521,7 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const transactionId = await client.wallet.sendToAddress(address, 0.00001)
- expect(typeof transactionId).toBe('string')
+ expect(typeof transactionId).toStrictEqual('string')
})
})
@@ -533,7 +533,7 @@ describe('masternode', () => {
}
const transactionId = await client.wallet.sendToAddress(address, 0.00001, options)
- expect(typeof transactionId).toBe('string')
+ expect(typeof transactionId).toStrictEqual('string')
})
})
@@ -544,7 +544,7 @@ describe('masternode', () => {
}
const transactionId = await client.wallet.sendToAddress(address, 0.00001, options)
- expect(typeof transactionId).toBe('string')
+ expect(typeof transactionId).toStrictEqual('string')
})
})
@@ -555,7 +555,7 @@ describe('masternode', () => {
}
const transactionId = await client.wallet.sendToAddress(address, 0.00001, options)
- expect(typeof transactionId).toBe('string')
+ expect(typeof transactionId).toStrictEqual('string')
})
})
@@ -566,7 +566,7 @@ describe('masternode', () => {
}
const transactionId = await client.wallet.sendToAddress(address, 0.00001, options)
- expect(typeof transactionId).toBe('string')
+ expect(typeof transactionId).toStrictEqual('string')
})
})
@@ -577,7 +577,7 @@ describe('masternode', () => {
}
const transactionId = await client.wallet.sendToAddress(address, 0.00001, options)
- expect(typeof transactionId).toBe('string')
+ expect(typeof transactionId).toStrictEqual('string')
})
})
})
@@ -587,8 +587,8 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const wallet = await client.wallet.createWallet('alice')
- expect(wallet.name).toBe('alice')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('alice')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
@@ -596,8 +596,8 @@ describe('masternode', () => {
return await waitForExpect(async () => {
const wallet = await client.wallet.createWallet('bob', true)
- expect(wallet.name).toBe('bob')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('bob')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
@@ -606,8 +606,8 @@ describe('masternode', () => {
const options = { blank: true }
const wallet = await client.wallet.createWallet('charlie', false, options)
- expect(wallet.name).toBe('charlie')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('charlie')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
@@ -616,8 +616,8 @@ describe('masternode', () => {
const options = { passphrase: 'shhh...' }
const wallet = await client.wallet.createWallet('david', false, options)
- expect(wallet.name).toBe('david')
- expect(wallet.warning).toBe('')
+ expect(wallet.name).toStrictEqual('david')
+ expect(wallet.warning).toStrictEqual('')
})
})
@@ -626,8 +626,8 @@ describe('masternode', () => {
const options = { avoidReuse: true }
const wallet = await client.wallet.createWallet('eve', false, options)
- expect(wallet.name).toBe('eve')
- expect(wallet.warning).toBe('Empty string given as passphrase, wallet will not be encrypted.')
+ expect(wallet.name).toStrictEqual('eve')
+ expect(wallet.warning).toStrictEqual('Empty string given as passphrase, wallet will not be encrypted.')
})
})
})
diff --git a/packages/jellyfish-api-core/__tests__/container_adapter_client.ts b/packages/jellyfish-api-core/__tests__/container_adapter_client.ts
index 13019e3560..a0a82ab515 100644
--- a/packages/jellyfish-api-core/__tests__/container_adapter_client.ts
+++ b/packages/jellyfish-api-core/__tests__/container_adapter_client.ts
@@ -30,8 +30,8 @@ export class ContainerAdapterClient extends ApiClient {
result: precision
})
- if (error !== undefined && error !== null) {
- throw new RpcApiError(error)
+ if (error != null) {
+ throw new RpcApiError({ ...error, method: method })
}
return result
diff --git a/packages/jellyfish-api-core/src/category/blockchain.ts b/packages/jellyfish-api-core/src/category/blockchain.ts
index 18fc2df497..b688dc7b0d 100644
--- a/packages/jellyfish-api-core/src/category/blockchain.ts
+++ b/packages/jellyfish-api-core/src/category/blockchain.ts
@@ -110,6 +110,15 @@ export class Blockchain {
return await this.client.call('getchaintips', [], 'number')
}
+ /**
+ * Get the proof-of-work difficulty as a multiple of the minimum difficulty.
+ *
+ * @return {Promise}
+ */
+ async getDifficulty (): Promise {
+ return await this.client.call('getdifficulty', [], 'number')
+ }
+
/**
* Get details of unspent transaction output (UTXO).
*
diff --git a/packages/jellyfish-api-core/src/category/mining.ts b/packages/jellyfish-api-core/src/category/mining.ts
index 0356445d02..7d5e87f33d 100644
--- a/packages/jellyfish-api-core/src/category/mining.ts
+++ b/packages/jellyfish-api-core/src/category/mining.ts
@@ -1,5 +1,11 @@
import { ApiClient } from '../.'
+export enum EstimateMode {
+ UNSET = 'UNSET',
+ ECONOMICAL = 'ECONOMICAL',
+ CONSERVATIVE = 'CONSERVATIVE'
+}
+
/**
* Mining RPCs for DeFi Blockchain
*/
@@ -37,6 +43,16 @@ export class Mining {
async getMiningInfo (): Promise {
return await this.client.call('getmininginfo', [], 'number')
}
+
+ /**
+ *
+ * @param {number} confirmationTarget in blocks (1 - 1008)
+ * @param {EstimateMode} [estimateMode=EstimateMode.CONSERVATIVE] estimateMode of fees.
+ * @returns {Promise}
+ */
+ async estimateSmartFee (confirmationTarget: number, estimateMode: EstimateMode = EstimateMode.CONSERVATIVE): Promise {
+ return await this.client.call('estimatesmartfee', [confirmationTarget, estimateMode], 'number')
+ }
}
/**
@@ -86,3 +102,9 @@ export interface MasternodeInfo {
mintedblocks?: number
lastblockcreationattempt?: string
}
+
+export interface SmartFeeEstimation {
+ feerate?: number
+ errors?: string[]
+ blocks: number
+}
diff --git a/packages/jellyfish-api-core/src/category/wallet.ts b/packages/jellyfish-api-core/src/category/wallet.ts
index cb4c71ed9f..ae5fcf5a34 100644
--- a/packages/jellyfish-api-core/src/category/wallet.ts
+++ b/packages/jellyfish-api-core/src/category/wallet.ts
@@ -191,7 +191,7 @@ export class Wallet {
replaceable = false,
confTarget = 6,
estimateMode = Mode.UNSET,
- avoidReuse = true
+ avoidReuse = false
} = options
return await this.client.call(
diff --git a/packages/jellyfish-api-core/src/index.ts b/packages/jellyfish-api-core/src/index.ts
index 88b5aebc82..6466339ef6 100644
--- a/packages/jellyfish-api-core/src/index.ts
+++ b/packages/jellyfish-api-core/src/index.ts
@@ -78,10 +78,10 @@ export class ClientApiError extends ApiError {
* API RPC error, from upstream.
*/
export class RpcApiError extends ApiError {
- public readonly payload: { code: number, message: string }
+ public readonly payload: { code: number, message: string, method: string }
- constructor (error: { code: number, message: string }) {
- super(`RpcApiError: '${error.message}', code: ${error.code}`)
+ constructor (error: { code: number, message: string, method: string }) {
+ super(`RpcApiError: '${error.message}', code: ${error.code}, method: ${error.method}`)
this.payload = error
}
}
diff --git a/packages/jellyfish-api-jsonrpc/__tests__/index.test.ts b/packages/jellyfish-api-jsonrpc/__tests__/index.test.ts
index 9f165ef4a6..a19c0c1cb9 100644
--- a/packages/jellyfish-api-jsonrpc/__tests__/index.test.ts
+++ b/packages/jellyfish-api-jsonrpc/__tests__/index.test.ts
@@ -29,12 +29,12 @@ describe('JSON-RPC 1.0 specification', () => {
const client = new JsonRpcClient('http://intercepted.defichain.node')
const result = await client.call('intercept', ['p1', 'p2'], 'number')
- await expect(result).toBe('intercepted')
+ await expect(result).toStrictEqual('intercepted')
- await expect(intercept.mock.calls[0][0].jsonrpc).toBe('1.0')
+ await expect(intercept.mock.calls[0][0].jsonrpc).toStrictEqual('1.0')
await expect(intercept.mock.calls[0][0].id).toBeGreaterThan(-1)
- await expect(intercept.mock.calls[0][0].method).toBe('intercept')
- await expect(intercept.mock.calls[0][0].params).toEqual(['p1', 'p2'])
+ await expect(intercept.mock.calls[0][0].method).toStrictEqual('intercept')
+ await expect(intercept.mock.calls[0][0].params).toStrictEqual(['p1', 'p2'])
})
it('generated id must be positive as per the spec', async () => {
@@ -43,7 +43,7 @@ describe('JSON-RPC 1.0 specification', () => {
for (const i of [...Array(100).keys()]) {
await client.call(`generate${i}`, [], 'number')
await expect(intercept.mock.calls[i][0].id).toBeGreaterThan(-1)
- await expect(intercept.mock.calls[i][0].id.toString()).not.toEqual(
+ await expect(intercept.mock.calls[i][0].id.toString()).not.toStrictEqual(
expect.not.stringMatching('.')
)
}
@@ -55,8 +55,8 @@ describe('JSON-RPC 1.0 specification', () => {
await client.call('generate1', [], 'number')
await client.call('generate2', [], 'number')
- await expect(intercept.mock.calls[0][0].id).not.toBe(intercept.mock.calls[1][0].id)
- await expect(intercept.mock.calls[1][0].id).not.toBe(intercept.mock.calls[2][0].id)
+ await expect(intercept.mock.calls[0][0].id).not.toStrictEqual(intercept.mock.calls[1][0].id)
+ await expect(intercept.mock.calls[1][0].id).not.toStrictEqual(intercept.mock.calls[2][0].id)
})
})
@@ -83,7 +83,7 @@ describe('ApiError', () => {
await expect(promise).rejects.toThrow(ApiError)
await expect(promise).rejects.toThrow(RpcApiError)
- await expect(promise).rejects.toThrow('RpcApiError: \'Invalid private key encoding\', code: -5')
+ await expect(promise).rejects.toThrow(/^RpcApiError: 'Invalid private key encoding', code: -5, method: importprivkey$/)
})
it('should throw ClientApiError: 404 - Not Found', async () => {
@@ -128,7 +128,7 @@ describe('ClientOptions', () => {
})
const result = await client.call('authorize', [], 'number')
- await expect(result).toBe('authorized')
+ await expect(result).toStrictEqual('authorized')
})
it('should timeout in 2 second', async () => {
diff --git a/packages/jellyfish-api-jsonrpc/src/index.ts b/packages/jellyfish-api-jsonrpc/src/index.ts
index 14e9b61cae..951fa2e959 100644
--- a/packages/jellyfish-api-jsonrpc/src/index.ts
+++ b/packages/jellyfish-api-jsonrpc/src/index.ts
@@ -67,7 +67,7 @@ export class JsonRpcClient extends ApiClient {
switch (response.status) {
case 200:
default:
- return JsonRpcClient.parse(text, precision)
+ return JsonRpcClient.parse(method, text, precision)
case 401:
case 404:
@@ -84,13 +84,13 @@ export class JsonRpcClient extends ApiClient {
})
}
- private static parse (text: string, precision: Precision | PrecisionPath): any {
+ private static parse (method: string, text: string, precision: Precision | PrecisionPath): any {
const { result, error } = JellyfishJSON.parse(text, {
result: precision
})
- if (error !== undefined && error !== null) {
- throw new RpcApiError(error)
+ if (error != null) {
+ throw new RpcApiError({ ...error, method: method })
}
return result
diff --git a/packages/jellyfish-crypto/__tests__/bech32.test.ts b/packages/jellyfish-crypto/__tests__/bech32.test.ts
index 9a182b41a5..564299a81a 100644
--- a/packages/jellyfish-crypto/__tests__/bech32.test.ts
+++ b/packages/jellyfish-crypto/__tests__/bech32.test.ts
@@ -12,7 +12,7 @@ it('should convert bech32 to hash160', () => {
const pubKey = Buffer.from(keypair.pubKey, 'hex')
const hash160 = HASH160(pubKey)
- expect(buffer.toString('hex')).toBe(hash160.toString('hex'))
+ expect(buffer.toString('hex')).toStrictEqual(hash160.toString('hex'))
})
it('should convert bech32 to hash160 with hrp and version', () => {
@@ -21,7 +21,7 @@ it('should convert bech32 to hash160 with hrp and version', () => {
const pubKey = Buffer.from(keypair.pubKey, 'hex')
const hash160 = HASH160(pubKey)
- expect(buffer.toString('hex')).toBe(hash160.toString('hex'))
+ expect(buffer.toString('hex')).toStrictEqual(hash160.toString('hex'))
})
it('should fail convert bech32 to pubkey with invalid hrp', () => {
@@ -40,7 +40,7 @@ it('should fail convert bech32 to pubkey with invalid version', () => {
it('should convert pubkey to bech32', () => {
const pubKey = Buffer.from(keypair.pubKey, 'hex')
const bech32 = Bech32.fromPubKey(pubKey, keypair.hrp)
- expect(bech32).toBe(keypair.bech32)
+ expect(bech32).toStrictEqual(keypair.bech32)
})
it('should reject non 33 bytes long input (expected public key)', () => {
@@ -53,11 +53,11 @@ it('should reject non 33 bytes long input (expected public key)', () => {
it('should convert pubkey to bech32 with witness version', () => {
const pubKey = Buffer.from(keypair.pubKey, 'hex')
const bech32 = Bech32.fromPubKey(pubKey, keypair.hrp, 0x00)
- expect(bech32).toBe(keypair.bech32)
+ expect(bech32).toStrictEqual(keypair.bech32)
})
it('should from bech32 to hash160 back to bech32', async () => {
const hash160: Buffer = Bech32.toHash160(keypair.bech32)
const bech32 = Bech32.fromHash160(hash160, keypair.hrp)
- expect(bech32).toBe(keypair.bech32)
+ expect(bech32).toStrictEqual(keypair.bech32)
})
diff --git a/packages/jellyfish-crypto/__tests__/bs58.test.ts b/packages/jellyfish-crypto/__tests__/bs58.test.ts
index fa857d47da..5f0f9b46aa 100644
--- a/packages/jellyfish-crypto/__tests__/bs58.test.ts
+++ b/packages/jellyfish-crypto/__tests__/bs58.test.ts
@@ -9,8 +9,8 @@ const fixture = {
describe('toHash160()', () => {
it('should convert base58 to hash160 + prefix', () => {
const decoded = Bs58.toHash160(fixture.base58)
- expect(decoded.prefix).toEqual(fixture.prefix)
- expect(decoded.buffer.toString('hex')).toEqual(fixture.h160)
+ expect(decoded.prefix).toStrictEqual(fixture.prefix)
+ expect(decoded.buffer.toString('hex')).toStrictEqual(fixture.h160)
})
it('should reject invalid address, invalid charset', async () => {
@@ -31,12 +31,12 @@ describe('toHash160()', () => {
describe('fromHash160()', () => {
it('should convert prefix + hash160 to base58', () => {
const address = Bs58.fromHash160(Buffer.from(fixture.h160, 'hex'), fixture.prefix)
- expect(address).toEqual(fixture.base58)
+ expect(address).toStrictEqual(fixture.base58)
})
it('should be able to take in hash160 string', () => {
const address = Bs58.fromHash160(fixture.h160, fixture.prefix)
- expect(address).toEqual(fixture.base58)
+ expect(address).toStrictEqual(fixture.base58)
})
it('should reject non 20 bytes long data', () => {
@@ -58,12 +58,12 @@ describe('fromPubKey()', () => {
const invalidPubKey = Buffer.from(thirdyThreeBytes.slice(2), 'hex') // less 1 byte
beforeAll(() => {
- expect(HASH160(pubKey).toString('hex')).toEqual(fixture.h160)
+ expect(HASH160(pubKey).toString('hex')).toStrictEqual(fixture.h160)
})
it('should convert prefix + hash160 to base58', () => {
const address = Bs58.fromPubKey(pubKey, fixture.prefix)
- expect(address).toEqual(fixture.base58)
+ expect(address).toStrictEqual(fixture.base58)
})
it('should reject non 33 bytes long data', () => {
diff --git a/packages/jellyfish-crypto/__tests__/elliptic.test.ts b/packages/jellyfish-crypto/__tests__/elliptic.test.ts
index 323cde9ef3..28f6cfcda2 100644
--- a/packages/jellyfish-crypto/__tests__/elliptic.test.ts
+++ b/packages/jellyfish-crypto/__tests__/elliptic.test.ts
@@ -8,7 +8,7 @@ it('should return privateKey from getEllipticPairFromPrivateKey ', async () => {
const curvePair = Elliptic.fromPrivKey(privateKey)
const getPrivKey: Buffer = await curvePair.privateKey()
- expect(getPrivKey.toString('hex')).toBe(privateKeyHex)
+ expect(getPrivKey.toString('hex')).toStrictEqual(privateKeyHex)
})
describe('keypair', () => {
@@ -20,7 +20,7 @@ describe('keypair', () => {
const curvePair = Elliptic.fromPrivKey(privateKey)
const getPubKey: Buffer = await curvePair.publicKey()
- expect(getPubKey.toString('hex')).toBe(publicKeyHex)
+ expect(getPubKey.toString('hex')).toStrictEqual(publicKeyHex)
})
it('should return privateKey from getEllipticPairFromPrivateKey ', async () => {
@@ -28,7 +28,7 @@ describe('keypair', () => {
const curvePair = Elliptic.fromPrivKey(privateKey)
const getPrivKey: Buffer = await curvePair.privateKey()
- expect(getPrivKey.toString('hex')).toBe(privateKeyHex)
+ expect(getPrivKey.toString('hex')).toStrictEqual(privateKeyHex)
})
})
@@ -38,7 +38,7 @@ describe('DER Signature: sign and verify', () => {
const curvePair = Elliptic.fromPrivKey(privateKey)
const getPubKey: Buffer = await curvePair.publicKey()
- expect(getPubKey.toString('hex')).toBe(publicKeyHex)
+ expect(getPubKey.toString('hex')).toStrictEqual(publicKeyHex)
}
async function shouldSignHashBufferGetSignature (privateKeyHex: string, hashHex: string, signatureHex: string): Promise {
@@ -47,7 +47,7 @@ describe('DER Signature: sign and verify', () => {
const hash = Buffer.from(hashHex, 'hex')
const signature = await curvePair.sign(hash)
- expect(signature.toString('hex')).toBe(signatureHex)
+ expect(signature.toString('hex')).toStrictEqual(signatureHex)
}
async function shouldVerifyHashWithSignature (privateKeyHex: string, hashHex: string, signatureHex: string): Promise {
@@ -58,7 +58,7 @@ describe('DER Signature: sign and verify', () => {
const signature = Buffer.from(signatureHex, 'hex')
const isValid = await curvePair.verify(hash, signature)
- expect(isValid).toBe(true)
+ expect(isValid).toStrictEqual(true)
}
describe('30 44<0220<>0220<>> 1', () => {
diff --git a/packages/jellyfish-crypto/__tests__/hash.test.ts b/packages/jellyfish-crypto/__tests__/hash.test.ts
index 2d27ed8633..c4ed99f0d3 100644
--- a/packages/jellyfish-crypto/__tests__/hash.test.ts
+++ b/packages/jellyfish-crypto/__tests__/hash.test.ts
@@ -3,17 +3,17 @@ import { dSHA256, HASH160, SHA256 } from '../src'
it('should sha256 with SHA256', () => {
const buffer = Buffer.from('56210307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba32103b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b21034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a21033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f42103a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac162102d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b56ae', 'hex')
const hashed = SHA256(buffer)
- expect(hashed.toString('hex')).toBe('a16b5755f7f6f96dbd65f5f0d6ab9418b89af4b1f14a1bb8a09062c35f0dcb54')
+ expect(hashed.toString('hex')).toStrictEqual('a16b5755f7f6f96dbd65f5f0d6ab9418b89af4b1f14a1bb8a09062c35f0dcb54')
})
it('should sha256(rmd160) with HASH160', () => {
const buffer = Buffer.from('025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357', 'hex')
const hashed = HASH160(buffer)
- expect(hashed.toString('hex')).toBe('1d0f172a0ecb48aee1be1f2687d2963ae33f71a1')
+ expect(hashed.toString('hex')).toStrictEqual('1d0f172a0ecb48aee1be1f2687d2963ae33f71a1')
})
it('should double sha256 with dSHA256', () => {
const buffer = Buffer.from('eeffffffffffffff', 'hex')
const hashed = dSHA256(buffer)
- expect(hashed.toString('hex')).toBe('52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b')
+ expect(hashed.toString('hex')).toStrictEqual('52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b')
})
diff --git a/packages/jellyfish-crypto/__tests__/index.test.ts b/packages/jellyfish-crypto/__tests__/index.test.ts
index 24e9215fd8..d896dfb0ad 100644
--- a/packages/jellyfish-crypto/__tests__/index.test.ts
+++ b/packages/jellyfish-crypto/__tests__/index.test.ts
@@ -10,7 +10,7 @@ describe('keySet 1', () => {
const wifDecoded = WIF.decode(keySet.wif)
const privKey = wifDecoded.privateKey
const pubKey = await Elliptic.fromPrivKey(privKey).publicKey()
- expect(Bech32.fromPubKey(pubKey, 'bcrt')).toBe(keySet.bech32)
+ expect(Bech32.fromPubKey(pubKey, 'bcrt')).toStrictEqual(keySet.bech32)
})
})
@@ -24,6 +24,6 @@ describe('keySet 2', () => {
const wifDecoded = WIF.decode(keySet.wif)
const privKey = wifDecoded.privateKey
const pubKey = await Elliptic.fromPrivKey(privKey).publicKey()
- expect(Bech32.fromPubKey(pubKey, 'bcrt')).toBe(keySet.bech32)
+ expect(Bech32.fromPubKey(pubKey, 'bcrt')).toStrictEqual(keySet.bech32)
})
})
diff --git a/packages/jellyfish-crypto/__tests__/wif.test.ts b/packages/jellyfish-crypto/__tests__/wif.test.ts
index 92165a09c8..da21add4cf 100644
--- a/packages/jellyfish-crypto/__tests__/wif.test.ts
+++ b/packages/jellyfish-crypto/__tests__/wif.test.ts
@@ -7,9 +7,9 @@ const pubKey = '03987aec2e508e124468f0f07a836d185b329026e7aaf75be48cf12be8f18cbe
it('should decode without version', () => {
const decoded = WIF.decode(REG_TEST_WIF)
- expect(decoded.version).toBe(0xef)
- expect(decoded.compressed).toBe(true)
- expect(decoded.privateKey.toString('hex')).toBe(privKey)
+ expect(decoded.version).toStrictEqual(0xef)
+ expect(decoded.compressed).toStrictEqual(true)
+ expect(decoded.privateKey.toString('hex')).toStrictEqual(privKey)
})
it('should decode with failed version', () => {
@@ -21,20 +21,20 @@ it('should decode with failed version', () => {
it('should decode with correct version', () => {
const decoded = WIF.decode(REG_TEST_WIF, 0xef)
- expect(decoded.version).toBe(0xef)
- expect(decoded.compressed).toBe(true)
- expect(decoded.privateKey.toString('hex')).toBe(privKey)
+ expect(decoded.version).toStrictEqual(0xef)
+ expect(decoded.compressed).toStrictEqual(true)
+ expect(decoded.privateKey.toString('hex')).toStrictEqual(privKey)
})
it('should decode decodeAsEllipticPair', async () => {
const pair = WIF.asEllipticPair(REG_TEST_WIF, 0xef)
const privateKey = await pair.privateKey()
const publicKey = await pair.publicKey()
- expect(privateKey.toString('hex')).toBe(privKey)
- expect(publicKey.toString('hex')).toBe(pubKey)
+ expect(privateKey.toString('hex')).toStrictEqual(privKey)
+ expect(publicKey.toString('hex')).toStrictEqual(pubKey)
})
it('should encode', () => {
const wif = WIF.encode(0xef, Buffer.from(privKey, 'hex'))
- expect(wif).toBe(REG_TEST_WIF)
+ expect(wif).toStrictEqual(REG_TEST_WIF)
})
diff --git a/packages/jellyfish-json/__tests__/index.test.ts b/packages/jellyfish-json/__tests__/index.test.ts
index a8acfd48b6..f5e5171728 100644
--- a/packages/jellyfish-json/__tests__/index.test.ts
+++ b/packages/jellyfish-json/__tests__/index.test.ts
@@ -5,12 +5,12 @@ describe('parse', () => {
/* eslint-disable @typescript-eslint/restrict-plus-operands */
it('18 digit significant should parse as lossless without precision lost', () => {
const obj = JellyfishJSON.parse('{"lossless":1200000000.00000001}', 'lossless')
- expect(obj.lossless.toString()).toBe('1200000000.00000001')
+ expect(obj.lossless.toString()).toStrictEqual('1200000000.00000001')
})
it('10 digit significant should parse as lossless with math operators should not have an error', () => {
const obj = JellyfishJSON.parse('{"lossless":1200000000}', 'lossless')
- expect((obj.lossless + 1).toString()).toBe('1200000001')
+ expect((obj.lossless + 1).toString()).toStrictEqual('1200000001')
})
it('18 digit significant should parse as lossless with math operators should throw an error', () => {
@@ -25,19 +25,19 @@ describe('parse', () => {
describe('bignumber', () => {
it('18 digit significant should parse as bignumber without precision lost', () => {
const obj = JellyfishJSON.parse('{"bignumber":1200000000.00000001}', 'bignumber')
- expect(obj.bignumber.toString()).toBe('1200000000.00000001')
+ expect(obj.bignumber.toString()).toStrictEqual('1200000000.00000001')
})
})
describe('number', () => {
it('18 digit significant should parse as number with precision lost', () => {
const obj = JellyfishJSON.parse('{"number":1200000000.00000001}', 'number')
- expect(obj.number.toString()).not.toBe('1200000000.00000001')
+ expect(obj.number.toString()).not.toStrictEqual('1200000000.00000001')
})
it('10 digit significant should parse as number without precision lost', () => {
const obj = JellyfishJSON.parse('{"number":1200000000}', 'number')
- expect(obj.number.toString()).toBe('1200000000')
+ expect(obj.number.toString()).toStrictEqual('1200000000')
})
})
})
@@ -47,21 +47,21 @@ describe('stringify', () => {
const string = JellyfishJSON.stringify({
number: Number('1200000000')
})
- expect(string).toBe('{"number":1200000000}')
+ expect(string).toStrictEqual('{"number":1200000000}')
})
it('should stringify lossless as json numeric', () => {
const string = JellyfishJSON.stringify({
lossless: new LosslessNumber('1200000000.00000001')
})
- expect(string).toBe('{"lossless":1200000000.00000001}')
+ expect(string).toStrictEqual('{"lossless":1200000000.00000001}')
})
it('should stringify bignumber as json number', () => {
const string = JellyfishJSON.stringify({
bignumber: new BigNumber('1200000000.00000001')
})
- expect(string).toBe('{"bignumber":1200000000.00000001}')
+ expect(string).toStrictEqual('{"bignumber":1200000000.00000001}')
})
})
@@ -73,6 +73,6 @@ it('should remap object at root with precision', () => {
big: 'bignumber'
})
- expect(parsed.big instanceof BigNumber).toBe(true)
- expect(parsed.num).toBe(1234)
+ expect(parsed.big instanceof BigNumber).toStrictEqual(true)
+ expect(parsed.num).toStrictEqual(1234)
})
diff --git a/packages/jellyfish-json/__tests__/precision.test.ts b/packages/jellyfish-json/__tests__/precision.test.ts
index 1144506294..041b4395b4 100644
--- a/packages/jellyfish-json/__tests__/precision.test.ts
+++ b/packages/jellyfish-json/__tests__/precision.test.ts
@@ -8,7 +8,7 @@ describe('number will lose precision', () => {
const dfi = 1200000000.00000003
expect(() => {
- expect(dfi.toString()).toBe('1200000000.00000003')
+ expect(dfi.toString()).toStrictEqual('1200000000.00000003')
}).toThrow()
})
@@ -17,7 +17,7 @@ describe('number will lose precision', () => {
const dfi = obj.dfi * 1000000
expect(() => {
- expect(dfi).toBe(12000000.03)
+ expect(dfi).toStrictEqual(12000000.03)
}).toThrow()
})
})
@@ -29,13 +29,13 @@ describe('BigNumber should not lose precision', () => {
it('1200000000.00000003 should not lose precision', () => {
const dfi = new BigNumber('1200000000.00000003')
- expect(dfi.toString()).toBe('1200000000.00000003')
+ expect(dfi.toString()).toStrictEqual('1200000000.00000003')
})
it('12.00000003 * 1000000 should be 12000000.03', () => {
const obj = { dfi: new BigNumber('12.00000003') }
const dfi = obj.dfi.multipliedBy(1000000)
- expect(dfi.toString()).toBe('12000000.03')
+ expect(dfi.toString()).toStrictEqual('12000000.03')
})
})
diff --git a/packages/jellyfish-json/__tests__/remap.test.ts b/packages/jellyfish-json/__tests__/remap.test.ts
index ef4ddd6f97..c6cdb2684b 100644
--- a/packages/jellyfish-json/__tests__/remap.test.ts
+++ b/packages/jellyfish-json/__tests__/remap.test.ts
@@ -34,26 +34,26 @@ it('should remap everything in the path', () => {
}
})
- expect(remapped.a instanceof BigNumber).toBe(true)
+ expect(remapped.a instanceof BigNumber).toStrictEqual(true)
- expect(remapped.b[0] instanceof BigNumber).toBe(true)
- expect(remapped.b[1] instanceof BigNumber).toBe(true)
+ expect(remapped.b[0] instanceof BigNumber).toStrictEqual(true)
+ expect(remapped.b[1] instanceof BigNumber).toStrictEqual(true)
- expect(remapped.c.c1 instanceof BigNumber).toBe(true)
- expect(remapped.c.c2[0] instanceof BigNumber).toBe(true)
+ expect(remapped.c.c1 instanceof BigNumber).toStrictEqual(true)
+ expect(remapped.c.c2[0] instanceof BigNumber).toStrictEqual(true)
- expect(remapped.d.e.e1 instanceof BigNumber).toBe(true)
- expect(remapped.d.e.e2[0] instanceof BigNumber).toBe(true)
- expect(remapped.d.e.e2[1] instanceof BigNumber).toBe(true)
+ expect(remapped.d.e.e1 instanceof BigNumber).toStrictEqual(true)
+ expect(remapped.d.e.e2[0] instanceof BigNumber).toStrictEqual(true)
+ expect(remapped.d.e.e2[1] instanceof BigNumber).toStrictEqual(true)
- expect(remapped.d.e.e3.e3a instanceof BigNumber).toBe(true)
- expect(remapped.d.e.e3.e3b[0] instanceof BigNumber).toBe(true)
+ expect(remapped.d.e.e3.e3a instanceof BigNumber).toStrictEqual(true)
+ expect(remapped.d.e.e3.e3b[0] instanceof BigNumber).toStrictEqual(true)
- expect(remapped.d.f.g instanceof BigNumber).toBe(true)
+ expect(remapped.d.f.g instanceof BigNumber).toStrictEqual(true)
- expect(remapped.d.f.f1).toBe(1.2)
+ expect(remapped.d.f.f1).toStrictEqual(1.2)
- expect(remapped.h).toBe(1.2)
+ expect(remapped.h).toStrictEqual(1.2)
})
function parseAndRemap (text: string, precision: PrecisionPath): any {
@@ -69,8 +69,8 @@ describe('remap individually', () => {
}`, {
big: 'bignumber'
})
- expect(parsed.big instanceof BigNumber).toBe(true)
- expect(parsed.num).toBe(1000)
+ expect(parsed.big instanceof BigNumber).toStrictEqual(true)
+ expect(parsed.num).toStrictEqual(1000)
})
it('should remap object deeply with precision', () => {
@@ -84,8 +84,8 @@ describe('remap individually', () => {
big: 'bignumber'
}
})
- expect(parsed.deeply.big instanceof BigNumber).toBe(true)
- expect(parsed.deeply.num).toBe(1000)
+ expect(parsed.deeply.big instanceof BigNumber).toStrictEqual(true)
+ expect(parsed.deeply.num).toStrictEqual(1000)
})
it('should remap array value with precision', () => {
@@ -98,8 +98,8 @@ describe('remap individually', () => {
array: 'bignumber'
})
- expect(remapped.array[0] instanceof BigNumber).toBe(true)
- expect(remapped.array[1] instanceof BigNumber).toBe(true)
+ expect(remapped.array[0] instanceof BigNumber).toStrictEqual(true)
+ expect(remapped.array[1] instanceof BigNumber).toStrictEqual(true)
})
it('should remap array object with precision', () => {
@@ -114,8 +114,8 @@ describe('remap individually', () => {
big: 'bignumber'
})
- expect(parsed[0].big instanceof BigNumber).toBe(true)
- expect(parsed[1].big instanceof BigNumber).toBe(true)
+ expect(parsed[0].big instanceof BigNumber).toStrictEqual(true)
+ expect(parsed[1].big instanceof BigNumber).toStrictEqual(true)
})
it('should remap array object with precision deeply', () => {
@@ -138,10 +138,10 @@ describe('remap individually', () => {
}
})
- expect(parsed[0].deeply.big instanceof BigNumber).toBe(true)
- expect(parsed[0].deeply.num).toBe(1)
- expect(parsed[1].deeply.big instanceof BigNumber).toBe(true)
- expect(parsed[1].deeply.num).toBe(1)
+ expect(parsed[0].deeply.big instanceof BigNumber).toStrictEqual(true)
+ expect(parsed[0].deeply.num).toStrictEqual(1)
+ expect(parsed[1].deeply.big instanceof BigNumber).toStrictEqual(true)
+ expect(parsed[1].deeply.num).toStrictEqual(1)
})
})
@@ -156,13 +156,13 @@ it('should remap lossless | number | bignumber', () => {
c: 'number'
})
- expect(parsed.a instanceof BigNumber).toBe(true)
- expect(parsed.a.toString()).toBe('1')
+ expect(parsed.a instanceof BigNumber).toStrictEqual(true)
+ expect(parsed.a.toString()).toStrictEqual('1')
- expect(parsed.b instanceof LosslessNumber).toBe(true)
- expect(parsed.b.toString()).toBe('2')
+ expect(parsed.b instanceof LosslessNumber).toStrictEqual(true)
+ expect(parsed.b.toString()).toStrictEqual('2')
- expect(parsed.c).toBe(3)
+ expect(parsed.c).toStrictEqual(3)
})
describe('remap invalid mapping should succeed', () => {
@@ -175,8 +175,8 @@ describe('remap invalid mapping should succeed', () => {
a: 'bignumber'
}
})
- expect(parsed.ignored).toBe(123.4)
- expect(parsed.num).toBe(1000)
+ expect(parsed.ignored).toStrictEqual(123.4)
+ expect(parsed.num).toStrictEqual(1000)
})
it('should ignore invalid null object', () => {
diff --git a/packages/jellyfish-network/__tests__/index.test.ts b/packages/jellyfish-network/__tests__/index.test.ts
index 93407807a8..066d0886ce 100644
--- a/packages/jellyfish-network/__tests__/index.test.ts
+++ b/packages/jellyfish-network/__tests__/index.test.ts
@@ -2,56 +2,56 @@ import { Network, MainNet, RegTest, TestNet, getNetwork } from '../src'
it('should be exported', () => {
const network: Network = MainNet
- expect(network.bech32.hrp).toBe('df')
- expect(network.wifPrefix).toBe(0x80)
+ expect(network.bech32.hrp).toStrictEqual('df')
+ expect(network.wifPrefix).toStrictEqual(0x80)
})
describe('getNetwork', () => {
it('should get mainnet', () => {
- expect(getNetwork('mainnet').name).toBe('mainnet')
- expect(getNetwork('mainnet').bech32.hrp).toBe('df')
+ expect(getNetwork('mainnet').name).toStrictEqual('mainnet')
+ expect(getNetwork('mainnet').bech32.hrp).toStrictEqual('df')
})
it('should get testnet', () => {
- expect(getNetwork('testnet').name).toBe('testnet')
- expect(getNetwork('testnet').bech32.hrp).toBe('tf')
+ expect(getNetwork('testnet').name).toStrictEqual('testnet')
+ expect(getNetwork('testnet').bech32.hrp).toStrictEqual('tf')
})
it('should get regtest', () => {
- expect(getNetwork('regtest').name).toBe('regtest')
- expect(getNetwork('regtest').bech32.hrp).toBe('bcrt')
+ expect(getNetwork('regtest').name).toStrictEqual('regtest')
+ expect(getNetwork('regtest').bech32.hrp).toStrictEqual('bcrt')
})
})
it('should match MainNet network', () => {
- expect(MainNet.name).toBe('mainnet')
- expect(MainNet.bech32.hrp).toBe('df')
- expect(MainNet.bip32.publicPrefix).toBe(0x0488b21e)
- expect(MainNet.bip32.privatePrefix).toBe(0x0488ade4)
- expect(MainNet.wifPrefix).toBe(0x80)
- expect(MainNet.pubKeyHashPrefix).toBe(0x12)
- expect(MainNet.scriptHashPrefix).toBe(0x5a)
- expect(MainNet.messagePrefix).toBe('\x15Defi Signed Message:\n')
+ expect(MainNet.name).toStrictEqual('mainnet')
+ expect(MainNet.bech32.hrp).toStrictEqual('df')
+ expect(MainNet.bip32.publicPrefix).toStrictEqual(0x0488b21e)
+ expect(MainNet.bip32.privatePrefix).toStrictEqual(0x0488ade4)
+ expect(MainNet.wifPrefix).toStrictEqual(0x80)
+ expect(MainNet.pubKeyHashPrefix).toStrictEqual(0x12)
+ expect(MainNet.scriptHashPrefix).toStrictEqual(0x5a)
+ expect(MainNet.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})
it('should match TestNet network', () => {
- expect(TestNet.name).toBe('testnet')
- expect(TestNet.bech32.hrp).toBe('tf')
- expect(TestNet.bip32.publicPrefix).toBe(0x043587cf)
- expect(TestNet.bip32.privatePrefix).toBe(0x04358394)
- expect(TestNet.wifPrefix).toBe(0xef)
- expect(TestNet.pubKeyHashPrefix).toBe(0xf)
- expect(TestNet.scriptHashPrefix).toBe(0x80)
- expect(TestNet.messagePrefix).toBe('\x15Defi Signed Message:\n')
+ expect(TestNet.name).toStrictEqual('testnet')
+ expect(TestNet.bech32.hrp).toStrictEqual('tf')
+ expect(TestNet.bip32.publicPrefix).toStrictEqual(0x043587cf)
+ expect(TestNet.bip32.privatePrefix).toStrictEqual(0x04358394)
+ expect(TestNet.wifPrefix).toStrictEqual(0xef)
+ expect(TestNet.pubKeyHashPrefix).toStrictEqual(0xf)
+ expect(TestNet.scriptHashPrefix).toStrictEqual(0x80)
+ expect(TestNet.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})
it('should match RegTest network', () => {
- expect(RegTest.name).toBe('regtest')
- expect(RegTest.bech32.hrp).toBe('bcrt')
- expect(RegTest.bip32.publicPrefix).toBe(0x043587cf)
- expect(RegTest.bip32.privatePrefix).toBe(0x04358394)
- expect(RegTest.wifPrefix).toBe(0xef)
- expect(RegTest.pubKeyHashPrefix).toBe(0x6f)
- expect(RegTest.scriptHashPrefix).toBe(0xc4)
- expect(RegTest.messagePrefix).toBe('\x15Defi Signed Message:\n')
+ expect(RegTest.name).toStrictEqual('regtest')
+ expect(RegTest.bech32.hrp).toStrictEqual('bcrt')
+ expect(RegTest.bip32.publicPrefix).toStrictEqual(0x043587cf)
+ expect(RegTest.bip32.privatePrefix).toStrictEqual(0x04358394)
+ expect(RegTest.wifPrefix).toStrictEqual(0xef)
+ expect(RegTest.pubKeyHashPrefix).toStrictEqual(0x6f)
+ expect(RegTest.scriptHashPrefix).toStrictEqual(0xc4)
+ expect(RegTest.messagePrefix).toStrictEqual('\x15Defi Signed Message:\n')
})
diff --git a/packages/jellyfish-transaction-builder/__tests__/raw_crafting.ts b/packages/jellyfish-transaction-builder/__tests__/raw_crafting.ts
index 4591b50945..0c74236892 100644
--- a/packages/jellyfish-transaction-builder/__tests__/raw_crafting.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/raw_crafting.ts
@@ -114,6 +114,6 @@ it('should craft, sign and broadcast a txn from scratch', async () => {
])
// Amount is exact to what I send and I can unlock it
- expect(unspent[0].amount).toBe(9.999)
- expect(unspent[0].spendable).toBe(true)
+ expect(unspent[0].amount).toStrictEqual(9.999)
+ expect(unspent[0].spendable).toStrictEqual(true)
})
diff --git a/packages/jellyfish-transaction-builder/__tests__/test.utils.ts b/packages/jellyfish-transaction-builder/__tests__/test.utils.ts
index bf42cffd49..226768e1b9 100644
--- a/packages/jellyfish-transaction-builder/__tests__/test.utils.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/test.utils.ts
@@ -71,11 +71,15 @@ export interface TxOut {
tokenId: number
}
-export async function findOut (outs: TxOut[], pair: EllipticPair): Promise {
+export async function findOuts (outs: TxOut[], pair: EllipticPair): Promise {
const pubKey = await pair.publicKey()
const address = Bech32.fromPubKey(pubKey, 'bcrt')
return outs.filter(value => {
- return value.scriptPubKey.addresses.includes(address)
- })[0]
+ return value.scriptPubKey.addresses?.includes(address)
+ })
+}
+
+export async function findOut (outs: TxOut[], pair: EllipticPair): Promise {
+ return (await findOuts(outs, pair))[0]
}
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_account_to_account.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_account_to_account.test.ts
new file mode 100644
index 0000000000..307e9cc673
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_account_to_account.test.ts
@@ -0,0 +1,244 @@
+import BigNumber from 'bignumber.js'
+import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
+import { OP_CODES } from '@defichain/jellyfish-transaction'
+import { AccountToAccount } from '@defichain/jellyfish-transaction/dist/script/defi/dftx_account'
+import { P2WPKH } from '@defichain/jellyfish-address'
+import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
+import { createToken, mintTokens, sendTokensToAddress, utxosToAccount } from '@defichain/testing'
+import { getProviders, MockProviders } from '../provider.mock'
+import { P2WPKHTransactionBuilder } from '../../src'
+import {
+ findOut,
+ fundEllipticPair,
+ sendTransaction
+} from '../test.utils'
+import { Bech32, HASH160 } from '@defichain/jellyfish-crypto'
+import { RegTest } from '@defichain/jellyfish-network'
+
+const container = new MasterNodeRegTestContainer()
+let providers: MockProviders
+let builder: P2WPKHTransactionBuilder
+let jsonRpc: JsonRpcClient
+
+let secondTokenId: number
+
+beforeAll(async () => {
+ await container.start()
+ await container.waitForReady()
+ await container.waitForWalletCoinbaseMaturity()
+ jsonRpc = new JsonRpcClient(await container.getCachedRpcUrl())
+
+ providers = await getProviders(container)
+
+ // Prep 1000 DFI Token for testing
+ await container.waitForWalletBalanceGTE(1001)
+
+ secondTokenId = await createToken(container, 'CAT')
+ await mintTokens(container, 'CAT', { mintAmount: 10000 })
+
+ // Ensure token created and minted can be sent
+ await container.generate(1)
+})
+
+afterAll(async () => {
+ await container.stop()
+})
+
+beforeEach(async () => {
+ await providers.randomizeEllipticPair()
+ await container.waitForWalletBalanceGTE(11.1)
+ builder = new P2WPKHTransactionBuilder(providers.fee, providers.prevout, providers.elliptic)
+
+ // Fund 10 DFI TOKEN
+ await fundEllipticPair(container, providers.ellipticPair, 10)
+ await providers.setupMocks() // required to move utxos
+ await utxosToAccount(container, 10, { address: await providers.getAddress() })
+
+ // Fund 1000 CAT TOKEN
+ await sendTokensToAddress(container, await providers.getAddress(), 1000, 'CAT')
+ await container.generate(1)
+
+ // Ensure starting balance
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain('10.00000000@DFI')
+ expect(account).toContain('1000.00000000@CAT')
+
+ // Fund 1 more DFI utxos for fee
+ await fundEllipticPair(container, providers.ellipticPair, 1)
+ await container.waitForWalletBalanceGTE(1)
+})
+
+describe('account.accountToAccount()', () => {
+ it('should receive token and change', async () => {
+ const newAddress = await container.getNewAddress()
+
+ // output token address
+ const newP2wpkh = P2WPKH.fromAddress(RegTest, newAddress, P2WPKH)
+
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const conversionAmount = 2.34 // amount converted into utxos
+ const accountToAccount: AccountToAccount = {
+ from: script,
+ to: [{
+ script: newP2wpkh.getScript(),
+ balances: [{
+ token: 0,
+ amount: new BigNumber(conversionAmount) // balance remaining in token
+ }]
+ }]
+ }
+
+ const txn = await builder.account.accountToAccount(accountToAccount, script)
+ const outs = await sendTransaction(container, txn)
+
+ expect(outs.length).toEqual(2)
+ const encoded: string = OP_CODES.OP_DEFI_TX_ACCOUNT_TO_ACCOUNT(accountToAccount).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+ expect(outs[0].tokenId).toEqual(0)
+
+ // change
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // burnt token
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain('7.66000000@DFI')
+
+ // minted token
+ const recipientAccount = await jsonRpc.account.getAccount(newAddress)
+ expect(recipientAccount).toContain('2.34000000@DFI')
+ })
+
+ it('should be able to transfer multiple token type', async () => {
+ const newAddress = await container.getNewAddress()
+
+ // output token address
+ const newP2wpkh = P2WPKH.fromAddress(RegTest, newAddress, P2WPKH)
+
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const dfiAmount = 2.34
+ const catAmount = 63.48
+
+ const accountToAccount: AccountToAccount = {
+ from: script,
+ to: [{
+ script: newP2wpkh.getScript(),
+ balances: [{
+ token: 0,
+ amount: new BigNumber(dfiAmount) // balance remaining in token
+ }, {
+ token: secondTokenId,
+ amount: new BigNumber(catAmount) // balance remaining in token
+ }]
+ }]
+ }
+
+ const txn = await builder.account.accountToAccount(accountToAccount, script)
+ const outs = await sendTransaction(container, txn)
+
+ expect(outs.length).toEqual(2)
+ const encoded: string = OP_CODES.OP_DEFI_TX_ACCOUNT_TO_ACCOUNT(accountToAccount).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+ expect(outs[0].tokenId).toEqual(0)
+
+ // change
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // burnt token
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain('7.66000000@DFI')
+ expect(account).toContain('936.52000000@CAT')
+
+ // minted token
+ const recipientAccount = await jsonRpc.account.getAccount(newAddress)
+ expect(recipientAccount).toContain('2.34000000@DFI')
+ expect(recipientAccount).toContain('63.48000000@CAT')
+ })
+
+ it('should be able to transfer to multiple destination address', async () => {
+ const destOneAddress = await container.getNewAddress()
+ const destTwoAddress = await container.getNewAddress()
+
+ // output token addresses
+ const destOneP2wpkh = P2WPKH.fromAddress(RegTest, destOneAddress, P2WPKH)
+ const destTwoP2wpkh = P2WPKH.fromAddress(RegTest, destTwoAddress, P2WPKH)
+
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const destOneAmount = 2.34
+ const destOneCatAmount = 77.77
+ const destTwoCatAmount = 63.48
+
+ const accountToAccount: AccountToAccount = {
+ from: script,
+ to: [{
+ script: destOneP2wpkh.getScript(),
+ balances: [{
+ token: 0,
+ amount: new BigNumber(destOneAmount)
+ }, {
+ token: secondTokenId,
+ amount: new BigNumber(destOneCatAmount)
+ }]
+ }, {
+ script: destTwoP2wpkh.getScript(),
+ balances: [{
+ token: secondTokenId,
+ amount: new BigNumber(destTwoCatAmount)
+ }]
+ }]
+ }
+
+ const txn = await builder.account.accountToAccount(accountToAccount, script)
+ const outs = await sendTransaction(container, txn)
+
+ expect(outs.length).toEqual(2)
+ const encoded: string = OP_CODES.OP_DEFI_TX_ACCOUNT_TO_ACCOUNT(accountToAccount).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+ expect(outs[0].tokenId).toEqual(0)
+
+ // change
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // burnt token
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+
+ expect(account).toContain('7.66000000@DFI')
+ expect(account).toContain('858.75000000@CAT')
+
+ // minted token
+ const recipientOneAccount = await jsonRpc.account.getAccount(destOneAddress)
+ expect(recipientOneAccount.length).toStrictEqual(2)
+ expect(recipientOneAccount).toContain('2.34000000@DFI')
+ expect(recipientOneAccount).toContain('77.77000000@CAT')
+
+ const recipientTwoAccount = await jsonRpc.account.getAccount(destTwoAddress)
+ expect(recipientTwoAccount.length).toStrictEqual(1)
+ expect(recipientTwoAccount).toContain('63.48000000@CAT')
+ })
+})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_account_to_utxos.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_account_to_utxos.test.ts
new file mode 100644
index 0000000000..316ebd9217
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_account_to_utxos.test.ts
@@ -0,0 +1,143 @@
+import BigNumber from 'bignumber.js'
+import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
+import { OP_CODES } from '@defichain/jellyfish-transaction'
+import { AccountToUtxos } from '@defichain/jellyfish-transaction/dist/script/defi/dftx_account'
+import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
+import { utxosToAccount } from '@defichain/testing'
+import { getProviders, MockProviders } from '../provider.mock'
+import { P2WPKHTransactionBuilder } from '../../src'
+import {
+ findOuts,
+ fundEllipticPair,
+ sendTransaction
+} from '../test.utils'
+import { Bech32, HASH160 } from '@defichain/jellyfish-crypto'
+
+const container = new MasterNodeRegTestContainer()
+let providers: MockProviders
+let builder: P2WPKHTransactionBuilder
+let jsonRpc: JsonRpcClient
+
+beforeAll(async () => {
+ await container.start()
+ await container.waitForReady()
+ await container.waitForWalletCoinbaseMaturity()
+ jsonRpc = new JsonRpcClient(await container.getCachedRpcUrl())
+ providers = await getProviders(container)
+
+ // Prep 1000 DFI UTXOS for testing
+ await container.waitForWalletBalanceGTE(1001)
+})
+
+afterAll(async () => {
+ await container.stop()
+})
+
+beforeEach(async () => {
+ await providers.randomizeEllipticPair()
+ await container.waitForWalletBalanceGTE(11.1)
+ builder = new P2WPKHTransactionBuilder(providers.fee, providers.prevout, providers.elliptic)
+
+ // Fund 10 DFI TOKEN
+ await providers.setupMocks() // required to move utxos
+ await utxosToAccount(container, 10, { address: await providers.getAddress() })
+
+ // Ensure starting balance
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain('10.00000000@DFI')
+
+ // Fund 1 DFI utxos for fee
+ await fundEllipticPair(container, providers.ellipticPair, 1)
+})
+
+describe('account.accountToUtxos()', () => {
+ it('should receive token and change', async () => {
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const conversionAmount = 2.34 // amount converted into utxos
+ const accountToUtxos: AccountToUtxos = {
+ from: script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(conversionAmount)
+ }],
+ mintingOutputsStart: 2
+ }
+
+ const txn = await builder.account.accountToUtxos(accountToUtxos, script)
+
+ const outs = await sendTransaction(container, txn)
+
+ expect(outs.length).toEqual(3)
+ const encoded: string = OP_CODES.OP_DEFI_TX_ACCOUNT_TO_UTXOS(accountToUtxos).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+ expect(outs[0].tokenId).toEqual(0)
+
+ const txOuts = await findOuts(outs, providers.elliptic.ellipticPair)
+ expect(txOuts.length).toStrictEqual(2)
+
+ const [change, minted] = txOuts
+ const expectedUtxosRedeemScript = `0014${HASH160(destPubKey).toString('hex')}`
+ const expectedOutAddress = Bech32.fromPubKey(destPubKey, 'bcrt')
+
+ // change returned
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(expectedUtxosRedeemScript)
+ expect(change.scriptPubKey.addresses[0]).toBe(expectedOutAddress)
+ expect(outs[1].scriptPubKey.addresses[0]).toStrictEqual(expectedOutAddress)
+
+ // minted utxos
+ expect(minted.value).toStrictEqual(conversionAmount)
+ expect(minted.scriptPubKey.hex).toBe(expectedUtxosRedeemScript)
+ expect(minted.scriptPubKey.addresses[0]).toBe(expectedOutAddress)
+ expect(outs[2].scriptPubKey.addresses[0]).toStrictEqual(expectedOutAddress)
+
+ // burnt token
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain('7.66000000@DFI')
+ })
+
+ it('should reject invalid accountToUtxos arg - more than 1 token in balance', async () => {
+ const script = await providers.elliptic.script()
+ await expect(builder.account.accountToUtxos({
+ from: script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(10)
+ }, {
+ token: 1,
+ amount: new BigNumber(10)
+ }],
+ mintingOutputsStart: 2
+ }, script)).rejects.toThrow('Conversion output `accountToUtxos.balances` array length must be one')
+ })
+
+ it('should reject invalid accountToUtxos arg - output token is not zero (DFI)', async () => {
+ const script = await providers.elliptic.script()
+ await expect(builder.account.accountToUtxos({
+ from: script,
+ balances: [{
+ token: 1,
+ amount: new BigNumber(10)
+ }],
+ mintingOutputsStart: 2
+ }, script)).rejects.toThrow('`accountToUtxos.balances[0].token` must be 0x00, only DFI support')
+ })
+
+ it('should reject invalid accountToUtxos arg - `mintingOutputsStart` is not two', async () => {
+ const script = await providers.elliptic.script()
+ await expect(builder.account.accountToUtxos({
+ from: script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(10)
+ }],
+ mintingOutputsStart: 1
+ }, script)).rejects.toThrow('`accountToUtxos.mintingOutputsStart` must be `2` for simplicity')
+ })
+})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_utxos_to_account.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_utxos_to_account.test.ts
new file mode 100644
index 0000000000..8723a5ca82
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_account_utxos_to_account.test.ts
@@ -0,0 +1,138 @@
+import BigNumber from 'bignumber.js'
+import { Bech32, HASH160 } from '@defichain/jellyfish-crypto'
+import { OP_CODES } from '@defichain/jellyfish-transaction'
+import { UtxosToAccount } from '@defichain/jellyfish-transaction/src/script/defi/dftx_account'
+import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
+import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
+import { getProviders, MockProviders } from '../provider.mock'
+import { P2WPKHTransactionBuilder } from '../../src'
+import {
+ findOut,
+ fundEllipticPair,
+ sendTransaction
+} from '../test.utils'
+
+const container = new MasterNodeRegTestContainer()
+let providers: MockProviders
+let builder: P2WPKHTransactionBuilder
+let jsonRpc: JsonRpcClient
+
+beforeAll(async () => {
+ await container.start()
+ await container.waitForReady()
+ await container.waitForWalletCoinbaseMaturity()
+
+ providers = await getProviders(container)
+ builder = new P2WPKHTransactionBuilder(providers.fee, providers.prevout, providers.elliptic)
+ jsonRpc = new JsonRpcClient(await container.getCachedRpcUrl())
+})
+
+afterAll(async () => {
+ await container.stop()
+})
+
+beforeEach(async () => {
+ await providers.randomizeEllipticPair()
+ await container.waitForWalletBalanceGTE(101)
+
+ // fund utxos balance
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 1.1) // 1.1
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 5.5) // 6.6
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 10.566) // 17.166
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 15.51345) // 32.67945
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 20) // 52.67945
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 37.98) // 90.65945
+ await fundEllipticPair(container, providers.elliptic.ellipticPair, 9.34055) // 100
+
+ await providers.setupMocks()
+})
+
+describe('account.utxosToAccount()', () => {
+ it('should receive token and change', async () => {
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const dest = await providers.elliptic.script()
+
+ const conversionAmount = 12.34
+
+ const utxosToAccount: UtxosToAccount = {
+ to: [{
+ balances: [{
+ token: 0x00,
+ amount: new BigNumber(conversionAmount)
+ }],
+ script: dest
+ }]
+ }
+
+ const txn = await builder.account.utxosToAccount(utxosToAccount, dest)
+
+ const outs = await sendTransaction(container, txn)
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+
+ expect(outs.length).toStrictEqual(2)
+ const encoded: string = OP_CODES.OP_DEFI_TX_UTXOS_TO_ACCOUNT(utxosToAccount).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toStrictEqual(conversionAmount)
+ expect(outs[0].scriptPubKey.hex).toStrictEqual(expectedRedeemScript)
+
+ expect(change.value).toBeLessThan(100 - conversionAmount)
+ expect(change.value).toBeGreaterThan(100 - conversionAmount - 0.001)
+ expect(change.scriptPubKey.hex).toStrictEqual(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // minted token
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account.length).toStrictEqual(1)
+ expect(account).toContain('12.34000000@DFI')
+ })
+
+ it('should reject invalid utxosToAccount arg - more than 1 token balances object', async () => {
+ const dest = await providers.elliptic.script()
+ await expect(builder.account.utxosToAccount({
+ to: [{
+ balances: [{
+ token: 0x00,
+ amount: new BigNumber(10)
+ }],
+ script: dest
+ }, {
+ balances: [{
+ token: 0x00,
+ amount: new BigNumber(10)
+ }],
+ script: dest
+ }]
+ }, dest)).rejects.toThrow('Conversion output `utxosToAccount.to` array length must be one')
+ })
+
+ // TODO: support multiple TokenBalance in `utxosToAccount.to` https://github.com/DeFiCh/jellyfish/issues/270
+ it('should reject invalid utxosToAccount arg - more than 1 token in balance', async () => {
+ const dest = await providers.elliptic.script()
+ await expect(builder.account.utxosToAccount({
+ to: [{
+ balances: [{
+ token: 0x00,
+ amount: new BigNumber(10)
+ }, {
+ token: 0x00,
+ amount: new BigNumber(10)
+ }],
+ script: dest
+ }]
+ }, dest)).rejects.toThrow('Conversion output `utxosToAccount.to[0].balances` array length must be one')
+ })
+
+ it('should reject invalid utxosToAccount arg - output token is not zero (DFI)', async () => {
+ const dest = await providers.elliptic.script()
+ await expect(builder.account.utxosToAccount({
+ to: [{
+ balances: [{
+ token: 0x01,
+ amount: new BigNumber(10)
+ }],
+ script: dest
+ }]
+ }, dest)).rejects.toThrow('`utxosToAccount.to[0].balances[0].token` must be 0x00, only DFI support')
+ })
+})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_dex_poolswap.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_dex_poolswap.test.ts
index fd9790b9d1..24eb4da5b7 100644
--- a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_dex_poolswap.test.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_dex_poolswap.test.ts
@@ -101,10 +101,10 @@ describe('DFI to DOG', () => {
// Ensure the created txn is correct.
const outs = await sendTransaction(container, txn)
- expect(outs[0].value).toBe(0)
+ expect(outs[0].value).toStrictEqual(0)
expect(outs[1].value).toBeLessThan(10)
expect(outs[1].value).toBeGreaterThan(9.999)
- expect(outs[1].scriptPubKey.addresses[0]).toBe(await providers.getAddress())
+ expect(outs[1].scriptPubKey.addresses[0]).toStrictEqual(await providers.getAddress())
// Ensure your balance is correct
const account = await jsonRpc.account.getAccount(await providers.getAddress())
@@ -115,13 +115,13 @@ describe('DFI to DOG', () => {
const pair = Object.values(poolPair)[0]
// Ensure correct pp liquidity and reverse balances
- expect(pair.totalLiquidity.toFixed(8)).toBe('100.00000000')
- expect(pair.reserveA.toFixed(8)).toBe('110.00000000')
- expect(pair.reserveB.toFixed(8)).toBe('90.90909090') // 100-9.09090910
+ expect(pair.totalLiquidity.toFixed(8)).toStrictEqual('100.00000000')
+ expect(pair.reserveA.toFixed(8)).toStrictEqual('110.00000000')
+ expect(pair.reserveB.toFixed(8)).toStrictEqual('90.90909090') // 100-9.09090910
// Ensure you don't send all your balance away during poolswap
const prevouts = await providers.prevout.all()
- expect(prevouts.length).toBe(1)
+ expect(prevouts.length).toStrictEqual(1)
expect(prevouts[0].value.toNumber()).toBeLessThan(10)
expect(prevouts[0].value.toNumber()).toBeGreaterThan(9.999)
})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_liq_pool_add_liquidity.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_liq_pool_add_liquidity.test.ts
new file mode 100644
index 0000000000..104962a185
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_liq_pool_add_liquidity.test.ts
@@ -0,0 +1,247 @@
+import BigNumber from 'bignumber.js'
+import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
+import { RegTest } from '@defichain/jellyfish-network'
+import { OP_CODES } from '@defichain/jellyfish-transaction'
+import { P2WPKH } from '@defichain/jellyfish-address'
+import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
+import { createPoolPair, createToken, mintTokens, sendTokensToAddress, utxosToAccount } from '@defichain/testing'
+import { getProviders, MockProviders } from '../provider.mock'
+import { P2WPKHTransactionBuilder } from '../../src'
+import {
+ findOut,
+ fundEllipticPair,
+ sendTransaction
+} from '../test.utils'
+import { Bech32, HASH160 } from '@defichain/jellyfish-crypto'
+import { PoolAddLiquidity } from '@defichain/jellyfish-transaction/dist/script/defi/dftx_pool'
+
+const container = new MasterNodeRegTestContainer()
+let providers: MockProviders
+let builder: P2WPKHTransactionBuilder
+let jsonRpc: JsonRpcClient
+
+let tokenId: number
+
+beforeAll(async () => {
+ await container.start()
+ await container.waitForReady()
+ await container.waitForWalletCoinbaseMaturity()
+ jsonRpc = new JsonRpcClient(await container.getCachedRpcUrl())
+ providers = await getProviders(container)
+
+ await container.waitForWalletBalanceGTE(1)
+
+ // Prep 10000 CAT Token for testing
+ tokenId = await createToken(container, 'CAT')
+ await mintTokens(container, 'CAT', { mintAmount: 10000 })
+ await createPoolPair(container, 'DFI', 'CAT')
+
+ // Prep 1000 DFI UTXOS for testing (for utxos to account)
+ await container.waitForWalletBalanceGTE(1001)
+})
+
+afterAll(async () => {
+ await container.stop()
+})
+
+beforeEach(async () => {
+ await providers.randomizeEllipticPair()
+ builder = new P2WPKHTransactionBuilder(providers.fee, providers.prevout, providers.elliptic)
+
+ // Fund 100 DFI TOKEN
+ await fundEllipticPair(container, providers.ellipticPair, 100)
+ await providers.setupMocks() // required to move utxos
+ await utxosToAccount(container, 100, { address: await providers.getAddress() })
+
+ // Fund 1000 CAT TOKEN
+ await sendTokensToAddress(container, await providers.getAddress(), 1000, 'CAT')
+ await container.generate(1)
+
+ // Ensure starting balance
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain('100.00000000@DFI')
+ expect(account).toContain('1000.00000000@CAT')
+
+ // Ensure zero starting pool share balance with this round test subject (new elliptic pair)
+ const address = await providers.getAddress()
+ const poolShares = await jsonRpc.poolpair.listPoolShares()
+ Object.values(poolShares).forEach((poolBal) => {
+ expect(poolBal.owner).not.toStrictEqual(address)
+ })
+
+ // Fund 1 DFI UTXOS for fee
+ await fundEllipticPair(container, providers.ellipticPair, 1)
+})
+
+describe('liqPool.addLiquidity()', () => {
+ it('should spend tokenA and tokenB, receive liquidity pair token', async () => {
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const tokenAAmount = 2.34
+ const tokenBAmount = 90.87
+ const addLiquidity: PoolAddLiquidity = {
+ from: [{
+ script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(tokenAAmount)
+ }, {
+ token: tokenId,
+ amount: new BigNumber(tokenBAmount)
+ }]
+ }],
+ shareAddress: script
+ }
+
+ const txn = await builder.liqPool.addLiquidity(addLiquidity, script)
+ const outs = await sendTransaction(container, txn)
+
+ expect(outs.length).toEqual(2)
+ const encoded: string = OP_CODES.OP_DEFI_TX_POOL_ADD_LIQUIDITY(addLiquidity).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+
+ // change
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // updated balance
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account.length).toStrictEqual(3)
+ expect(account).toContain('97.66000000@DFI')
+ expect(account).toContain('909.13000000@CAT')
+
+ // minted LM token
+ const lmTokenFound = account.find(tb => tb.split('@')[1] === 'DFI-CAT')
+ expect(lmTokenFound).toBeTruthy()
+
+ // found in pool share listing
+ const poolShares = await jsonRpc.poolpair.listPoolShares()
+ const accountPoolBal = poolShares[`2@${await providers.getAddress()}`]
+ expect(accountPoolBal.owner).toStrictEqual(await providers.getAddress())
+ expect(accountPoolBal.poolID).toStrictEqual('2') // 0 = DFI, 1 = CAT, 2 = DFI-CAT
+ expect(accountPoolBal.amount.gt(0)).toBeTruthy()
+ })
+
+ it('should be able to store output shares in any p2wpkh address', async () => {
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const shareDestAddress = await container.getNewAddress()
+ const shareDest = P2WPKH.fromAddress(RegTest, shareDestAddress, P2WPKH)
+
+ const tokenAAmount = 2.34
+ const tokenBAmount = 90.87
+ const addLiquidity: PoolAddLiquidity = {
+ from: [{
+ script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(tokenAAmount)
+ }, {
+ token: tokenId,
+ amount: new BigNumber(tokenBAmount)
+ }]
+ }],
+ shareAddress: shareDest.getScript()
+ }
+
+ const txn = await builder.liqPool.addLiquidity(addLiquidity, script)
+ const outs = await sendTransaction(container, txn)
+
+ expect(outs.length).toEqual(2)
+ const encoded: string = OP_CODES.OP_DEFI_TX_POOL_ADD_LIQUIDITY(addLiquidity).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+
+ // change
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // updated balance
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account.length).toStrictEqual(2)
+ expect(account).toContain('97.66000000@DFI')
+ expect(account).toContain('909.13000000@CAT')
+
+ // minted LM token
+ const shareDestAcc = await jsonRpc.account.getAccount(shareDestAddress)
+ const lmTokenFound = shareDestAcc.find(tb => tb.split('@')[1] === 'DFI-CAT')
+ expect(lmTokenFound).toBeTruthy()
+
+ // found in pool share listing
+ const poolShares = await jsonRpc.poolpair.listPoolShares()
+ const accountPoolBal = poolShares[`2@${shareDestAddress}`]
+ expect(accountPoolBal.owner).toStrictEqual(shareDestAddress)
+ expect(accountPoolBal.poolID).toStrictEqual('2') // 0 = DFI, 1 = CAT, 2 = DFI-CAT
+ expect(accountPoolBal.amount.gt(0)).toBeTruthy()
+ })
+
+ it('should reject invalid addLiquidity arg - more than 1 in `from`', async () => {
+ const script = await providers.elliptic.script()
+ await expect(builder.liqPool.addLiquidity({
+ from: [{
+ script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(10)
+ }]
+ }, {
+ script,
+ balances: [{
+ token: 1,
+ amount: new BigNumber(10)
+ }]
+ }],
+ shareAddress: script
+ }, script)).rejects.toThrow('`addLiquidity.from` array length must be ONE')
+ })
+
+ it('should reject invalid addLiquidity arg - not 2 TokenBalance in `from.balances`', async () => {
+ const script = await providers.elliptic.script()
+ await expect(builder.liqPool.addLiquidity({
+ from: [{
+ script,
+ balances: [{
+ token: 0,
+ amount: new BigNumber(10)
+ }, {
+ token: 0,
+ amount: new BigNumber(10)
+ }, {
+ token: 1,
+ amount: new BigNumber(10)
+ }]
+ }],
+ shareAddress: script
+ }, script)).rejects.toThrow('`addLiquidity.from[0].balances` array length must be TWO')
+ })
+
+ it('should reject invalid addLiquidity arg - `from.balances` is not a valid pair', async () => {
+ const script = await providers.elliptic.script()
+ await expect(builder.liqPool.addLiquidity({
+ from: [{
+ script,
+ balances: [{
+ token: 1,
+ amount: new BigNumber(10)
+ }, {
+ token: 1,
+ amount: new BigNumber(10)
+ }]
+ }],
+ shareAddress: script
+ }, script)).rejects.toThrow('`addLiquidity.from[0].balances` must consists of TWO different token')
+ })
+})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_liq_pool_remove_liquidity.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_liq_pool_remove_liquidity.test.ts
new file mode 100644
index 0000000000..a63b8fb39d
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_liq_pool_remove_liquidity.test.ts
@@ -0,0 +1,122 @@
+import BigNumber from 'bignumber.js'
+import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
+import { OP_CODES } from '@defichain/jellyfish-transaction'
+import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
+import { addPoolLiquidity, createPoolPair, createToken, mintTokens } from '@defichain/testing'
+import { getProviders, MockProviders } from '../provider.mock'
+import { P2WPKHTransactionBuilder } from '../../src'
+import {
+ findOut,
+ fundEllipticPair,
+ sendTransaction
+} from '../test.utils'
+import { Bech32, HASH160 } from '@defichain/jellyfish-crypto'
+import { PoolRemoveLiquidity } from '@defichain/jellyfish-transaction/dist/script/defi/dftx_pool'
+
+const container = new MasterNodeRegTestContainer()
+let providers: MockProviders
+let builder: P2WPKHTransactionBuilder
+let jsonRpc: JsonRpcClient
+
+let tokenId: number
+
+let address: string
+let amount: BigNumber
+
+beforeAll(async () => {
+ await container.start()
+ await container.waitForReady()
+ await container.waitForWalletCoinbaseMaturity()
+ jsonRpc = new JsonRpcClient(await container.getCachedRpcUrl())
+
+ providers = await getProviders(container)
+
+ await container.waitForWalletBalanceGTE(1)
+
+ // Prep 10000 CAT Token for testing
+ tokenId = await createToken(container, 'CAT')
+ await mintTokens(container, 'CAT', { mintAmount: 10000 })
+ await createPoolPair(container, 'DFI', 'CAT')
+
+ // other wise the new DFI-CAT tokenId cannot be 2
+ expect(tokenId).toStrictEqual(1)
+})
+
+afterAll(async () => {
+ await container.stop()
+})
+
+beforeEach(async () => {
+ await providers.randomizeEllipticPair()
+ await providers.setupMocks() // required to move utxos
+ builder = new P2WPKHTransactionBuilder(providers.fee, providers.prevout, providers.elliptic)
+
+ await container.waitForWalletBalanceGTE(1)
+
+ address = await providers.getAddress()
+ amount = await addPoolLiquidity(container, {
+ tokenA: 'DFI',
+ amountA: 100,
+ tokenB: 'CAT',
+ amountB: 100,
+ shareAddress: address
+ })
+
+ // Fund 1 DFI UTXOS for fee
+ await fundEllipticPair(container, providers.ellipticPair, 1)
+
+ // Ensure starting balances
+ await container.generate(1)
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account).toContain(`${amount.toFixed(8)}@DFI-CAT`)
+})
+
+describe('liqPool.removeLiquidity()', () => {
+ it('should burn liquidity pair token, receive tokenA and tokenB', async () => {
+ const destPubKey = await providers.ellipticPair.publicKey()
+ const script = await providers.elliptic.script()
+
+ const removeLiquidity: PoolRemoveLiquidity = {
+ script,
+ tokenId: 2,
+ amount
+ }
+
+ const txn = await builder.liqPool.removeLiquidity(removeLiquidity, script)
+ const outs = await sendTransaction(container, txn)
+ expect(outs.length).toEqual(2)
+
+ const encoded: string = OP_CODES.OP_DEFI_TX_POOL_REMOVE_LIQUIDITY(removeLiquidity).asBuffer().toString('hex')
+ // OP_RETURN + DfTx full buffer
+ const expectedRedeemScript = `6a${encoded}`
+ expect(outs[0].value).toEqual(0)
+ expect(outs[0].scriptPubKey.hex).toEqual(expectedRedeemScript)
+
+ // change
+ const change = await findOut(outs, providers.elliptic.ellipticPair)
+ expect(change.value).toBeLessThan(1)
+ expect(change.value).toBeGreaterThan(1 - 0.001) // deducted fee
+ expect(change.scriptPubKey.hex).toBe(`0014${HASH160(destPubKey).toString('hex')}`)
+ expect(change.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(destPubKey, 'bcrt'))
+
+ // updated balance, receive invidual token
+ const account = await jsonRpc.account.getAccount(await providers.getAddress())
+ expect(account.length).toStrictEqual(2)
+
+ const balances: Map = new Map()
+ account.forEach(tokenBalance => {
+ const [bal, tokenSymbol] = tokenBalance.split('@')
+ balances.set(tokenSymbol, new BigNumber(bal))
+ })
+
+ const dfiBal = balances.get('DFI')
+ const catBal = balances.get('CAT')
+ const lmBal = balances.get('DFI-CAT')
+
+ expect(dfiBal?.gt(99.999)).toBeTruthy()
+ expect(dfiBal?.lt(100)).toBeTruthy()
+ expect(catBal?.gt(99.999)).toBeTruthy()
+ expect(catBal?.lt(100)).toBeTruthy()
+ expect(lmBal).toBeFalsy()
+ })
+})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_p2wpkh.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_p2wpkh.test.ts
index 3e8caf4e34..84904b3ec2 100644
--- a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_p2wpkh.test.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_p2wpkh.test.ts
@@ -58,27 +58,27 @@ describe('createDeFiTx()', () => {
const change = await providers.elliptic.script()
const result = await builder.createDeFiTx(dummyDfTx, change)
- expect(result.vin.length).toEqual(7)
- expect(result.vout.length).toEqual(2) // 1 DfTx, 1 change
- expect(result.vout[0].value).toEqual(new BigNumber(0))
- expect(result.vout[1].script).toEqual(change)
+ expect(result.vin.length).toStrictEqual(7)
+ expect(result.vout.length).toStrictEqual(2) // 1 DfTx, 1 change
+ expect(result.vout[0].value).toStrictEqual(new BigNumber(0))
+ expect(result.vout[1].script).toStrictEqual(change)
// under normal (non test) env, only required amount of prevout will be taken and aggregated
// test provider here simply collect everything
expect(result.vout[1].value.gt(99.999)).toBeTruthy()
expect(result.vout[1].value.lt(100)).toBeTruthy()
- expect(result.vout[0].script.stack.length).toEqual(2)
- expect(result.vout[0].script.stack[0]).toEqual(OP_CODES.OP_RETURN)
- expect(result.vout[0].script.stack[1].type).toEqual('OP_DEFI_TX')
+ expect(result.vout[0].script.stack.length).toStrictEqual(2)
+ expect(result.vout[0].script.stack[0]).toStrictEqual(OP_CODES.OP_RETURN)
+ expect(result.vout[0].script.stack[1].type).toStrictEqual('OP_DEFI_TX')
const tx = (result.vout[0].script.stack[1] as OP_DEFI_TX).tx
- expect(tx.signature).toBe(1147556984)
- expect(tx.type).toBe(0x01)
- expect(tx.name).toBe('OP_DEFI_TX_UNMAPPED')
+ expect(tx.signature).toStrictEqual(1147556984)
+ expect(tx.type).toStrictEqual(0x01)
+ expect(tx.name).toStrictEqual('OP_DEFI_TX_UNMAPPED')
const unmapped = tx.data as DeFiOpUnmapped
- expect(unmapped.hex).toBe('001234')
+ expect(unmapped.hex).toStrictEqual('001234')
})
it('balance should be deducted accordingly based on spent on DfTx', async () => {
@@ -87,10 +87,10 @@ describe('createDeFiTx()', () => {
const change = await providers.elliptic.script()
const result = await builder.createDeFiTx(dummyDfTx, change, spendAmount)
- expect(result.vin.length).toEqual(7)
- expect(result.vout.length).toEqual(2) // 1 DfTx, 1 change
- expect(result.vout[0].value).toEqual(spendAmount)
- expect(result.vout[1].script).toEqual(change)
+ expect(result.vin.length).toStrictEqual(7)
+ expect(result.vout.length).toStrictEqual(2) // 1 DfTx, 1 change
+ expect(result.vout[0].value).toStrictEqual(spendAmount)
+ expect(result.vout[1].script).toStrictEqual(change)
expect(result.vout[1].value.gt(new BigNumber(99.999).minus(spendAmount))).toBeTruthy()
expect(result.vout[1].value.lt(new BigNumber(100).minus(spendAmount))).toBeTruthy()
})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo.test.ts
index 720b27444c..270b2c7cd4 100644
--- a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo.test.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo.test.ts
@@ -51,26 +51,26 @@ describe('utxo.send', () => {
const outs = await sendTransaction(container, txn)
const sendTo = await findOut(outs, sendPair)
- expect(sendTo.value).toBe(5)
- expect(sendTo.scriptPubKey.hex).toBe(`0014${HASH160(sendPubKey).toString('hex')}`)
- expect(sendTo.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(sendPubKey, 'bcrt'))
+ expect(sendTo.value).toStrictEqual(5)
+ expect(sendTo.scriptPubKey.hex).toStrictEqual(`0014${HASH160(sendPubKey).toString('hex')}`)
+ expect(sendTo.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(sendPubKey, 'bcrt'))
const changePair = await providers.elliptic.ellipticPair
const changePubKey = await changePair.publicKey()
const changeTo = await findOut(outs, providers.elliptic.ellipticPair)
expect(changeTo.value).toBeGreaterThan(4.99)
expect(changeTo.value).toBeLessThan(5)
- expect(changeTo.scriptPubKey.hex).toBe(`0014${HASH160(changePubKey).toString('hex')}`)
- expect(changeTo.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(changePubKey, 'bcrt'))
+ expect(changeTo.scriptPubKey.hex).toStrictEqual(`0014${HASH160(changePubKey).toString('hex')}`)
+ expect(changeTo.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(changePubKey, 'bcrt'))
const prevouts = await providers.prevout.all()
- expect(prevouts.length).toBe(1)
- expect(prevouts[0].value.toNumber()).toBe(changeTo.value)
- expect(prevouts[0].vout).toBe(changeTo.n)
+ expect(prevouts.length).toStrictEqual(1)
+ expect(prevouts[0].value.toNumber()).toStrictEqual(changeTo.value)
+ expect(prevouts[0].vout).toStrictEqual(changeTo.n)
- expect(prevouts[0].script.stack.length).toBe(2)
- expect(prevouts[0].script.stack[0].type).toBe('OP_0')
- expect((prevouts[0].script.stack[1] as OP_PUSHDATA).hex).toBe(HASH160(changePubKey).toString('hex'))
+ expect(prevouts[0].script.stack.length).toStrictEqual(2)
+ expect(prevouts[0].script.stack[0].type).toStrictEqual('OP_0')
+ expect((prevouts[0].script.stack[1] as OP_PUSHDATA).hex).toStrictEqual(HASH160(changePubKey).toString('hex'))
})
// TODO(ivan-zynesis): other address types
@@ -90,16 +90,16 @@ describe('utxo.sendAll', () => {
const txn = await builder.utxo.sendAll(to)
const outs = await sendTransaction(container, txn)
- expect(outs.length).toBe(1)
+ expect(outs.length).toStrictEqual(1)
const sendTo = await findOut(outs, sendPair)
expect(sendTo.value).toBeGreaterThan(9.99)
expect(sendTo.value).toBeLessThan(10)
- expect(sendTo.scriptPubKey.hex).toBe(`0014${HASH160(sendPubKey).toString('hex')}`)
- expect(sendTo.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(sendPubKey, 'bcrt'))
+ expect(sendTo.scriptPubKey.hex).toStrictEqual(`0014${HASH160(sendPubKey).toString('hex')}`)
+ expect(sendTo.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(sendPubKey, 'bcrt'))
const prevouts = await providers.prevout.all()
- expect(prevouts.length).toBe(0)
+ expect(prevouts.length).toStrictEqual(0)
})
// TODO(ivan-zynesis): other address types
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo_many.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo_many.test.ts
index add0350fdb..8c46a3dbfd 100644
--- a/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo_many.test.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/txn/txn_builder_utxo_many.test.ts
@@ -59,26 +59,26 @@ describe('utxo.send', () => {
const outs = await sendTransaction(container, txn)
const sendTo = await findOut(outs, sendPair)
- expect(sendTo.value).toBe(99)
- expect(sendTo.scriptPubKey.hex).toBe(`0014${HASH160(sendPubKey).toString('hex')}`)
- expect(sendTo.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(sendPubKey, 'bcrt'))
+ expect(sendTo.value).toStrictEqual(99)
+ expect(sendTo.scriptPubKey.hex).toStrictEqual(`0014${HASH160(sendPubKey).toString('hex')}`)
+ expect(sendTo.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(sendPubKey, 'bcrt'))
const changePair = await providers.elliptic.ellipticPair
const changePubKey = await changePair.publicKey()
const changeTo = await findOut(outs, providers.elliptic.ellipticPair)
expect(changeTo.value).toBeGreaterThan(0.9)
expect(changeTo.value).toBeLessThan(1)
- expect(changeTo.scriptPubKey.hex).toBe(`0014${HASH160(changePubKey).toString('hex')}`)
- expect(changeTo.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(changePubKey, 'bcrt'))
+ expect(changeTo.scriptPubKey.hex).toStrictEqual(`0014${HASH160(changePubKey).toString('hex')}`)
+ expect(changeTo.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(changePubKey, 'bcrt'))
const prevouts = await providers.prevout.all()
- expect(prevouts.length).toBe(1)
- expect(prevouts[0].value.toNumber()).toBe(changeTo.value)
- expect(prevouts[0].vout).toBe(changeTo.n)
+ expect(prevouts.length).toStrictEqual(1)
+ expect(prevouts[0].value.toNumber()).toStrictEqual(changeTo.value)
+ expect(prevouts[0].vout).toStrictEqual(changeTo.n)
- expect(prevouts[0].script.stack.length).toBe(2)
- expect(prevouts[0].script.stack[0].type).toBe('OP_0')
- expect((prevouts[0].script.stack[1] as OP_PUSHDATA).hex).toBe(HASH160(changePubKey).toString('hex'))
+ expect(prevouts[0].script.stack.length).toStrictEqual(2)
+ expect(prevouts[0].script.stack[0].type).toStrictEqual('OP_0')
+ expect((prevouts[0].script.stack[1] as OP_PUSHDATA).hex).toStrictEqual(HASH160(changePubKey).toString('hex'))
})
})
@@ -96,15 +96,15 @@ describe('utxo.sendAll', () => {
const txn = await builder.utxo.sendAll(to)
const outs = await sendTransaction(container, txn)
- expect(outs.length).toBe(1)
+ expect(outs.length).toStrictEqual(1)
const sendTo = await findOut(outs, sendPair)
expect(sendTo.value).toBeGreaterThan(99.99)
expect(sendTo.value).toBeLessThan(100)
- expect(sendTo.scriptPubKey.hex).toBe(`0014${HASH160(sendPubKey).toString('hex')}`)
- expect(sendTo.scriptPubKey.addresses[0]).toBe(Bech32.fromPubKey(sendPubKey, 'bcrt'))
+ expect(sendTo.scriptPubKey.hex).toStrictEqual(`0014${HASH160(sendPubKey).toString('hex')}`)
+ expect(sendTo.scriptPubKey.addresses[0]).toStrictEqual(Bech32.fromPubKey(sendPubKey, 'bcrt'))
const prevouts = await providers.prevout.all()
- expect(prevouts.length).toBe(0)
+ expect(prevouts.length).toStrictEqual(0)
})
})
diff --git a/packages/jellyfish-transaction-builder/__tests__/txn_fee.test.ts b/packages/jellyfish-transaction-builder/__tests__/txn_fee.test.ts
index 5876b84bf2..17149567ee 100644
--- a/packages/jellyfish-transaction-builder/__tests__/txn_fee.test.ts
+++ b/packages/jellyfish-transaction-builder/__tests__/txn_fee.test.ts
@@ -12,17 +12,17 @@ import {
describe('dust amount', () => {
it('0.00001 should be dust amount', () => {
const amount = new BigNumber('0.00001')
- expect(isDustAmount(amount)).toBe(true)
+ expect(isDustAmount(amount)).toStrictEqual(true)
})
it('0.00003 should be dust amount', () => {
const amount = new BigNumber('0.00003')
- expect(isDustAmount(amount)).toBe(true)
+ expect(isDustAmount(amount)).toStrictEqual(true)
})
it('0.000031 should not be dust amount', () => {
const amount = new BigNumber('0.000031')
- expect(isDustAmount(amount)).toBe(false)
+ expect(isDustAmount(amount)).toStrictEqual(false)
})
})
@@ -119,7 +119,7 @@ describe('calculate fee for p2wpkh', () => {
vout: [P2WPKH_VOUT],
lockTime: 0x00000000
}
- expect(calculateFeeP2WPKH(fee, transaction).toFixed(8)).toBe('0.00007425')
+ expect(calculateFeeP2WPKH(fee, transaction).toFixed(8)).toStrictEqual('0.00007425')
})
it('[P2WPKH_VIN] to [P2WPKH_VOUT, P2WPKH_VOUT] with fee 0.0006689 DFI/kb', () => {
@@ -130,7 +130,7 @@ describe('calculate fee for p2wpkh', () => {
vout: [P2WPKH_VOUT, P2WPKH_VOUT],
lockTime: 0x00000000
}
- expect(calculateFeeP2WPKH(fee, transaction).toFixed(8)).toBe('0.00009565')
+ expect(calculateFeeP2WPKH(fee, transaction).toFixed(8)).toStrictEqual('0.00009565')
})
})
@@ -146,7 +146,7 @@ describe('calculate fee', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateFee(fee, transaction, witness).toFixed(8)).toBe('0.00000333')
+ expect(calculateFee(fee, transaction, witness).toFixed(8)).toStrictEqual('0.00000333')
})
it('[P2WPKH_VIN] to [P2WPKH_VOUT] with fee 0.00010000 DFI/kb', () => {
@@ -160,7 +160,7 @@ describe('calculate fee', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateFee(fee, transaction, witness).toFixed(8)).toBe('0.00001110')
+ expect(calculateFee(fee, transaction, witness).toFixed(8)).toStrictEqual('0.00001110')
})
it('[P2WPKH_VIN] to [P2WPKH_VOUT] with fee 0.0006689 DFI/kb', () => {
@@ -174,7 +174,7 @@ describe('calculate fee', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateFee(fee, transaction, witness).toFixed(8)).toBe('0.00007425')
+ expect(calculateFee(fee, transaction, witness).toFixed(8)).toStrictEqual('0.00007425')
})
it('[P2WPKH_VIN] to [P2WPKH_VOUT, P2WPKH_VOUT] with fee 0.0006689 DFI/kb', () => {
@@ -188,7 +188,7 @@ describe('calculate fee', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateFee(fee, transaction, witness).toFixed(8)).toBe('0.00009565')
+ expect(calculateFee(fee, transaction, witness).toFixed(8)).toStrictEqual('0.00009565')
})
})
@@ -203,7 +203,7 @@ describe('virtual size', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateVirtual(transaction, witness)).toBe(111)
+ expect(calculateVirtual(transaction, witness)).toStrictEqual(111)
})
it('[P2SH_P2WPKH_VIN] to [P2SH_VOUT,P2SH_VOUT]', () => {
@@ -216,7 +216,7 @@ describe('virtual size', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateVirtual(transaction, witness)).toBe(168)
+ expect(calculateVirtual(transaction, witness)).toStrictEqual(168)
})
})
@@ -231,7 +231,7 @@ describe('weight', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateWeight(transaction, witness)).toBe(441)
+ expect(calculateWeight(transaction, witness)).toStrictEqual(441)
})
it('[P2WPKH_VIN] to [P2WSH_VOUT, P2PKH_VOUT]', () => {
@@ -242,7 +242,7 @@ describe('weight', () => {
lockTime: 0x00000000
}
const witness: Witness[] = []
- expect(calculateWeight(transaction, witness)).toBe(814)
+ expect(calculateWeight(transaction, witness)).toStrictEqual(814)
})
it('[P2SH_P2WPKH_VIN] to [P2SH_VOUT,P2SH_VOUT]', () => {
@@ -255,6 +255,6 @@ describe('weight', () => {
const witness: Witness[] = [
P2WPKH_WITNESS
]
- expect(calculateWeight(transaction, witness)).toBe(669)
+ expect(calculateWeight(transaction, witness)).toStrictEqual(669)
})
})
diff --git a/packages/jellyfish-transaction-builder/src/index.ts b/packages/jellyfish-transaction-builder/src/index.ts
index e08e564210..9da0b6d16d 100644
--- a/packages/jellyfish-transaction-builder/src/index.ts
+++ b/packages/jellyfish-transaction-builder/src/index.ts
@@ -1,6 +1,8 @@
import { P2WPKHTxnBuilder } from './txn/txn_builder'
import { TxnBuilderDex } from './txn/txn_builder_dex'
import { TxnBuilderUtxo } from './txn/txn_builder_utxo'
+import { TxnBuilderAccount } from './txn/txn_builder_account'
+import { TxnBuilderLiqPool } from './txn/txn_builder_liq_pool'
export * from './provider'
export * from './txn/txn_fee'
@@ -15,4 +17,6 @@ export * from './txn/txn_builder_utxo'
export class P2WPKHTransactionBuilder extends P2WPKHTxnBuilder {
public readonly dex = new TxnBuilderDex(this.feeProvider, this.prevoutProvider, this.ellipticPairProvider)
public readonly utxo = new TxnBuilderUtxo(this.feeProvider, this.prevoutProvider, this.ellipticPairProvider)
+ public readonly account = new TxnBuilderAccount(this.feeProvider, this.prevoutProvider, this.ellipticPairProvider)
+ public readonly liqPool = new TxnBuilderLiqPool(this.feeProvider, this.prevoutProvider, this.ellipticPairProvider)
}
diff --git a/packages/jellyfish-transaction-builder/src/txn/txn_builder_account.ts b/packages/jellyfish-transaction-builder/src/txn/txn_builder_account.ts
new file mode 100644
index 0000000000..393eb3ed30
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/src/txn/txn_builder_account.ts
@@ -0,0 +1,117 @@
+import BigNumber from 'bignumber.js'
+import { AccountToAccount, AccountToUtxos, UtxosToAccount } from '@defichain/jellyfish-transaction/dist/script/defi/dftx_account'
+import { DeFiTransactionConstants, OP_CODES, Script, Transaction, TransactionSegWit, Vout } from '@defichain/jellyfish-transaction'
+import { P2WPKHTxnBuilder } from './txn_builder'
+import { TxnBuilderError, TxnBuilderErrorType } from './txn_builder_error'
+
+export class TxnBuilderAccount extends P2WPKHTxnBuilder {
+ /**
+ * Requires UTXO in the same amount + fees to create a transaction.
+ *
+ * @param {UtxosToAccount} utxosToAccount txn to create
+ * @param {Script} changeScript to send unspent to after deducting the (converted + fees)
+ * @throws {TxnBuilderError} if 'utxosToAccount.to' and 'utxosToAccount.to[0].balances' length is not `1`
+ * @throws {TxnBuilderError} if 'utxosToAccount.to' and 'utxosToAccount.to[0].balances[0].token' is not `0`
+ * @returns {Promise}
+ */
+ async utxosToAccount (utxosToAccount: UtxosToAccount, changeScript: Script): Promise {
+ if (utxosToAccount.to.length !== 1) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_UTXOS_TO_ACCOUNT_OUTPUT,
+ 'Conversion output `utxosToAccount.to` array length must be one'
+ )
+ }
+
+ if (utxosToAccount.to[0].balances.length !== 1) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_UTXOS_TO_ACCOUNT_OUTPUT,
+ 'Conversion output `utxosToAccount.to[0].balances` array length must be one'
+ )
+ }
+
+ if (utxosToAccount.to[0].balances[0].token !== 0x00) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_UTXOS_TO_ACCOUNT_OUTPUT,
+ '`utxosToAccount.to[0].balances[0].token` must be 0x00, only DFI support'
+ )
+ }
+
+ const amountToConvert = utxosToAccount.to[0].balances[0].amount
+ return await super.createDeFiTx(
+ OP_CODES.OP_DEFI_TX_UTXOS_TO_ACCOUNT(utxosToAccount),
+ changeScript,
+ amountToConvert
+ )
+ }
+
+ /**
+ *
+ * @param {AccountToUtxos} accountToUtxos txn to create
+ * @param {Script} destinationScript vout destination, for both utxos minted and change after deducted fee
+ * @throws {TxnBuilderError} if 'accountToUtxos.balances' length is not `1`
+ * @throws {TxnBuilderError} if 'accountToUtxos.balances[0].token' is not `0`
+ * @throws {TxnBuilderError} if 'accountToUtxos.mintingOutputsStart' is not `2`, vout[0] = DfTx, vout[1] = change, vout[2] = new minted utxos
+ * @returns {Promise}
+ */
+ async accountToUtxos (accountToUtxos: AccountToUtxos, destinationScript: Script): Promise {
+ if (accountToUtxos.balances.length !== 1) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_ACCOUNT_TO_UTXOS_INPUT,
+ 'Conversion output `accountToUtxos.balances` array length must be one'
+ )
+ }
+
+ if (accountToUtxos.balances[0].token !== 0x00) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_ACCOUNT_TO_UTXOS_INPUT,
+ '`accountToUtxos.balances[0].token` must be 0x00, only DFI support'
+ )
+ }
+
+ if (accountToUtxos.mintingOutputsStart !== 2) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_ACCOUNT_TO_UTXOS_INPUT,
+ '`accountToUtxos.mintingOutputsStart` must be `2` for simplicity'
+ )
+ }
+
+ const minFee = new BigNumber(0.001)
+ const { prevouts, vin, total } = await this.collectPrevouts(minFee)
+
+ const deFiOut: Vout = {
+ value: new BigNumber(0),
+ script: {
+ stack: [
+ OP_CODES.OP_RETURN,
+ OP_CODES.OP_DEFI_TX_ACCOUNT_TO_UTXOS(accountToUtxos)
+ ]
+ },
+ tokenId: 0x00
+ }
+
+ const out: Vout = {
+ value: accountToUtxos.balances[0].amount,
+ script: destinationScript,
+ tokenId: 0x00
+ }
+
+ const change: Vout = {
+ value: total,
+ script: destinationScript,
+ tokenId: 0x00
+ }
+
+ const txn: Transaction = {
+ version: DeFiTransactionConstants.Version,
+ vin: vin,
+ vout: [deFiOut, change, out],
+ lockTime: 0x00000000
+ }
+
+ const fee = await this.calculateFee(txn)
+ change.value = total.minus(fee)
+
+ return await this.sign(txn, prevouts)
+ }
+
+ async accountToAccount (accountToAccount: AccountToAccount, changeScript: Script): Promise {
+ return await super.createDeFiTx(
+ OP_CODES.OP_DEFI_TX_ACCOUNT_TO_ACCOUNT(accountToAccount),
+ changeScript
+ )
+ }
+}
diff --git a/packages/jellyfish-transaction-builder/src/txn/txn_builder_error.ts b/packages/jellyfish-transaction-builder/src/txn/txn_builder_error.ts
index fda2481e30..693411c29b 100644
--- a/packages/jellyfish-transaction-builder/src/txn/txn_builder_error.ts
+++ b/packages/jellyfish-transaction-builder/src/txn/txn_builder_error.ts
@@ -18,7 +18,19 @@ export enum TxnBuilderErrorType {
/**
* Unable to sign transaction due to error in TransactionSigner
*/
- SIGN_TRANSACTION_ERROR
+ SIGN_TRANSACTION_ERROR,
+ /**
+ * Invalid conversion output `TokenBalance`, must consist only valid DFI balance
+ */
+ INVALID_UTXOS_TO_ACCOUNT_OUTPUT,
+ /**
+ * Invalid input `TokenBalances` array length must be one
+ */
+ INVALID_ADD_LIQUIDITY_INPUT,
+ /**
+ * Invalid conversion input `TokenBalances`, must consist only valid DFI balance
+ */
+ INVALID_ACCOUNT_TO_UTXOS_INPUT
}
/**
diff --git a/packages/jellyfish-transaction-builder/src/txn/txn_builder_liq_pool.ts b/packages/jellyfish-transaction-builder/src/txn/txn_builder_liq_pool.ts
new file mode 100644
index 0000000000..7959d2aecd
--- /dev/null
+++ b/packages/jellyfish-transaction-builder/src/txn/txn_builder_liq_pool.ts
@@ -0,0 +1,54 @@
+import { PoolAddLiquidity, PoolRemoveLiquidity } from '@defichain/jellyfish-transaction/dist/script/defi/dftx_pool'
+import { OP_CODES, Script, TransactionSegWit } from '@defichain/jellyfish-transaction'
+import { P2WPKHTxnBuilder } from './txn_builder'
+import { TxnBuilderError, TxnBuilderErrorType } from './txn_builder_error'
+
+export class TxnBuilderLiqPool extends P2WPKHTxnBuilder {
+ /**
+ * Add to liquidity pool using token balances pair supplied in `addLiquidity`.from[0].balances.
+ *
+ * @param {PoolAddLiquidity} addLiquidity txn to create
+ * @param {Script} changeScript to send unspent to after deducting the (converted + fees)
+ * @throws {TxnBuilderError} if 'addLiquidity.from' length is not `1`
+ * @throws {TxnBuilderError} if 'addLiquidity.from[0].balances' length is not `2`
+ * @returns {Promise}
+ */
+ async addLiquidity (addLiquidity: PoolAddLiquidity, changeScript: Script): Promise {
+ if (addLiquidity.from.length !== 1) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_ADD_LIQUIDITY_INPUT,
+ '`addLiquidity.from` array length must be ONE'
+ )
+ }
+
+ if (addLiquidity.from[0].balances.length !== 2) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_ADD_LIQUIDITY_INPUT,
+ '`addLiquidity.from[0].balances` array length must be TWO'
+ )
+ }
+
+ if (addLiquidity.from[0].balances[0].token === addLiquidity.from[0].balances[1].token) {
+ throw new TxnBuilderError(TxnBuilderErrorType.INVALID_ADD_LIQUIDITY_INPUT,
+ '`addLiquidity.from[0].balances` must consists of TWO different token'
+ )
+ }
+
+ return await this.createDeFiTx(
+ OP_CODES.OP_DEFI_TX_POOL_ADD_LIQUIDITY(addLiquidity),
+ changeScript
+ )
+ }
+
+ /**
+ * Remove from liquidity pool.
+ *
+ * @param {PoolRemoveLiquidity} removeLiquidity pool token p2pwkh scipt, token id and amount to remove
+ * @param {Script} changeScript to send unspent to after deducting the (converted + fees)
+ * @returns {Promise}
+ */
+ async removeLiquidity (removeLiquidity: PoolRemoveLiquidity, changeScript: Script): Promise {
+ return await this.createDeFiTx(
+ OP_CODES.OP_DEFI_TX_POOL_REMOVE_LIQUIDITY(removeLiquidity),
+ changeScript
+ )
+ }
+}
diff --git a/packages/jellyfish-transaction/__tests__/buffer/buffer_composer.test.ts b/packages/jellyfish-transaction/__tests__/buffer/buffer_composer.test.ts
index dffd8fb66c..0c2f55ab90 100644
--- a/packages/jellyfish-transaction/__tests__/buffer/buffer_composer.test.ts
+++ b/packages/jellyfish-transaction/__tests__/buffer/buffer_composer.test.ts
@@ -27,12 +27,12 @@ it('should format (4 bytes, 32 bytes, 8 bytes) hex with hexAsBufferLE', () => {
'01aa535d3d0c0000'
])
expect(buffer.toString('hex'))
- .toBe('00080008fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f01aa535d3d0c0000')
+ .toStrictEqual('00080008fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f01aa535d3d0c0000')
})
function shouldFromBuffer (composer: BufferComposer, hex: string | string[], val: T, getter: () => T): void {
composer.fromBuffer(hexAsBuffer(hex))
- expect(getter()).toEqual(val)
+ expect(getter()).toStrictEqual(val)
}
function shouldToBuffer (composer: BufferComposer, hex: string | string[], val: T, setter: (v: T) => void): void {
@@ -40,7 +40,7 @@ function shouldToBuffer (composer: BufferComposer, hex: string | string[], va
const buffer: SmartBuffer = new SmartBuffer()
composer.toBuffer(buffer)
const expected: SmartBuffer = hexAsBuffer(hex)
- expect(buffer.toString('hex')).toBe(expected.toString('hex'))
+ expect(buffer.toString('hex')).toStrictEqual(expected.toString('hex'))
}
describe('ComposableBuffer deep implementation', () => {
@@ -137,19 +137,19 @@ describe('ComposableBuffer deep implementation', () => {
const buffer = new SmartBuffer()
root.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toBe(hex)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
it('CRoot to JSON deeply compare', () => {
const root = new CRoot(data)
- expect(JSON.stringify(root.toObject())).toBe(JSON.stringify(data))
+ expect(JSON.stringify(root.toObject())).toStrictEqual(JSON.stringify(data))
})
it('buffer to CRoot', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
const root = new CRoot(buffer)
- expect(JSON.stringify(root.toObject())).toBe(JSON.stringify(data))
+ expect(JSON.stringify(root.toObject())).toStrictEqual(JSON.stringify(data))
})
})
@@ -160,14 +160,14 @@ describe('ComposableBuffer.empty', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from('0001', 'hex'))
composer.toBuffer(buffer)
- expect(buffer.readUInt8()).toBe(0)
+ expect(buffer.readUInt8()).toStrictEqual(0)
})
it('fromBuffer should do nothing', () => {
const buffer = new SmartBuffer()
composer.fromBuffer(buffer)
- expect(buffer.length).toBe(0)
+ expect(buffer.length).toStrictEqual(0)
})
})
@@ -409,7 +409,7 @@ describe('ComposableBuffer.hex', () => {
it('should fromBuffer', () => {
composer.fromBuffer(SmartBuffer.fromBuffer(expectedBuffer))
- expect(value).toBe('9ea83a5c6579d282d189cc04b8e151ef')
+ expect(value).toStrictEqual('9ea83a5c6579d282d189cc04b8e151ef')
})
it('should toBuffer', () => {
@@ -418,7 +418,7 @@ describe('ComposableBuffer.hex', () => {
const buffer = new SmartBuffer()
composer.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toBe(expectedBuffer.toString('hex'))
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(expectedBuffer.toString('hex'))
})
it('should not have side effect when reading and writing', () => {
@@ -427,7 +427,7 @@ describe('ComposableBuffer.hex', () => {
const to = new SmartBuffer()
composer.toBuffer(to)
- expect(from.toString()).toBe(to.toString())
+ expect(from.toString()).toStrictEqual(to.toString())
})
it('should fail toBuffer validate', () => {
@@ -447,7 +447,7 @@ describe('ComposableBuffer.hexBE', () => {
it('should fromBuffer', () => {
composer.fromBuffer(SmartBuffer.fromBuffer(expectedBuffer))
- expect(value).toBe('ef51e1b804cc89d182d279655c3aa89e')
+ expect(value).toStrictEqual('ef51e1b804cc89d182d279655c3aa89e')
})
it('should toBuffer', () => {
@@ -456,7 +456,7 @@ describe('ComposableBuffer.hexBE', () => {
const buffer = new SmartBuffer()
composer.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toBe(expectedBuffer.toString('hex'))
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(expectedBuffer.toString('hex'))
})
it('should not have side effect when reading and writing', () => {
@@ -465,7 +465,7 @@ describe('ComposableBuffer.hexBE', () => {
const to = new SmartBuffer()
composer.toBuffer(to)
- expect(from.toString()).toBe(to.toString())
+ expect(from.toString()).toStrictEqual(to.toString())
})
it('should fail toBuffer validate', () => {
@@ -485,7 +485,7 @@ describe('ComposableBuffer.utf8LE', () => {
it('should fromBuffer', () => {
composer.fromBuffer(SmartBuffer.fromBuffer(expectedBuffer))
- expect(value).toBe('DFI-BTC')
+ expect(value).toStrictEqual('DFI-BTC')
})
it('should toBuffer', () => {
@@ -494,7 +494,7 @@ describe('ComposableBuffer.utf8LE', () => {
const buffer = new SmartBuffer()
composer.toBuffer(buffer)
- expect(buffer.toBuffer().toString('utf-8')).toBe(expectedBuffer.toString('utf-8'))
+ expect(buffer.toBuffer().toString('utf-8')).toStrictEqual(expectedBuffer.toString('utf-8'))
})
it('should not have side effect when reading and writing', () => {
@@ -503,7 +503,7 @@ describe('ComposableBuffer.utf8LE', () => {
const to = new SmartBuffer()
composer.toBuffer(to)
- expect(from.toString()).toBe(to.toString())
+ expect(from.toString()).toStrictEqual(to.toString())
})
it('should fail toBuffer validate', () => {
@@ -523,7 +523,7 @@ describe('ComposableBuffer.utf8BE', () => {
it('should fromBuffer', () => {
composer.fromBuffer(SmartBuffer.fromBuffer(expectedBuffer))
- expect(value).toBe('DeFi Blockchain')
+ expect(value).toStrictEqual('DeFi Blockchain')
})
it('should toBuffer', () => {
@@ -532,7 +532,7 @@ describe('ComposableBuffer.utf8BE', () => {
const buffer = new SmartBuffer()
composer.toBuffer(buffer)
- expect(buffer.toBuffer().toString('utf-8')).toBe(expectedBuffer.toString('utf-8'))
+ expect(buffer.toBuffer().toString('utf-8')).toStrictEqual(expectedBuffer.toString('utf-8'))
})
it('should not have side effect when reading and writing', () => {
@@ -541,7 +541,7 @@ describe('ComposableBuffer.utf8BE', () => {
const to = new SmartBuffer()
composer.toBuffer(to)
- expect(from.toString()).toBe(to.toString())
+ expect(from.toString()).toStrictEqual(to.toString())
})
it('should fail toBuffer validate', () => {
@@ -564,7 +564,7 @@ describe('ComposableBuffer.varUIntUtf8LE', () => {
it('should fromBuffer', () => {
composer.fromBuffer(SmartBuffer.fromBuffer(expectedBuffer))
- expect(value).toBe('DFI-DFI-DFI-DFI-BTC')
+ expect(value).toStrictEqual('DFI-DFI-DFI-DFI-BTC')
})
it('should toBuffer', () => {
@@ -573,7 +573,7 @@ describe('ComposableBuffer.varUIntUtf8LE', () => {
const buffer = new SmartBuffer()
composer.toBuffer(buffer)
- expect(buffer.toBuffer().toString('utf-8')).toBe(expectedBuffer.toString('utf-8'))
+ expect(buffer.toBuffer().toString('utf-8')).toStrictEqual(expectedBuffer.toString('utf-8'))
})
it('should not have side effect when reading and writing', () => {
@@ -582,7 +582,7 @@ describe('ComposableBuffer.varUIntUtf8LE', () => {
const to = new SmartBuffer()
composer.toBuffer(to)
- expect(from.toString()).toBe(to.toString())
+ expect(from.toString()).toStrictEqual(to.toString())
})
})
@@ -597,7 +597,7 @@ describe('ComposableBuffer.varUIntUtf8BE', () => {
it('should fromBuffer', () => {
composer.fromBuffer(SmartBuffer.fromBuffer(expectedBuffer))
- expect(value).toBe('DFI-ETH-BTC-DFI')
+ expect(value).toStrictEqual('DFI-ETH-BTC-DFI')
})
it('should toBuffer', () => {
@@ -606,7 +606,7 @@ describe('ComposableBuffer.varUIntUtf8BE', () => {
const buffer = new SmartBuffer()
composer.toBuffer(buffer)
- expect(buffer.toBuffer().toString('utf-8')).toBe(expectedBuffer.toString('utf-8'))
+ expect(buffer.toBuffer().toString('utf-8')).toStrictEqual(expectedBuffer.toString('utf-8'))
})
it('should not have side effect when reading and writing', () => {
@@ -615,7 +615,7 @@ describe('ComposableBuffer.varUIntUtf8BE', () => {
const to = new SmartBuffer()
composer.toBuffer(to)
- expect(from.toString()).toBe(to.toString())
+ expect(from.toString()).toStrictEqual(to.toString())
})
})
@@ -940,7 +940,7 @@ describe('ComposableBuffer.varUInt', () => {
buffer.writeUInt16LE(0x03e8)
composer.fromBuffer(buffer)
- expect(value).toBe(1000)
+ expect(value).toStrictEqual(1000)
})
it('should toBuffer', () => {
@@ -950,7 +950,7 @@ describe('ComposableBuffer.varUInt', () => {
composer.toBuffer(buffer)
const expected = Buffer.from('fde803', 'hex')
- expect(buffer.toString()).toBe(expected.toString())
+ expect(buffer.toString()).toStrictEqual(expected.toString())
})
})
@@ -961,7 +961,7 @@ describe('ComposableBuffer.varUInt', () => {
buffer.writeUInt32LE(0x000186a0)
composer.fromBuffer(buffer)
- expect(value).toBe(100000)
+ expect(value).toStrictEqual(100000)
})
it('should toBuffer', () => {
@@ -971,7 +971,7 @@ describe('ComposableBuffer.varUInt', () => {
composer.toBuffer(buffer)
const expected = Buffer.from('fea0860100', 'hex')
- expect(buffer.toString()).toBe(expected.toString())
+ expect(buffer.toString()).toStrictEqual(expected.toString())
})
})
@@ -982,7 +982,7 @@ describe('ComposableBuffer.varUInt', () => {
buffer.writeBigInt64LE(BigInt(10000000000))
composer.fromBuffer(buffer)
- expect(value).toBe(10000000000)
+ expect(value).toStrictEqual(10000000000)
})
it('should toBuffer', () => {
@@ -992,7 +992,7 @@ describe('ComposableBuffer.varUInt', () => {
composer.toBuffer(buffer)
const expected = Buffer.from('ff00e40b5402000000', 'hex')
- expect(buffer.toString()).toBe(expected.toString())
+ expect(buffer.toString()).toStrictEqual(expected.toString())
})
})
diff --git a/packages/jellyfish-transaction/__tests__/buffer/buffer_varuint.test.ts b/packages/jellyfish-transaction/__tests__/buffer/buffer_varuint.test.ts
index febbb16ef6..9da04ab7b3 100644
--- a/packages/jellyfish-transaction/__tests__/buffer/buffer_varuint.test.ts
+++ b/packages/jellyfish-transaction/__tests__/buffer/buffer_varuint.test.ts
@@ -12,7 +12,7 @@ it('readBigInt64LE should be equal (readUInt32LE + readUInt32LE * 0x100000000)',
const hi = buffer.readUInt32LE(4)
const num = lo + (hi * 0x100000000)
- expect(bigInt.toString()).toBe(num.toString())
+ expect(bigInt.toString()).toStrictEqual(num.toString())
})
describe('writeVarUInt', () => {
@@ -25,80 +25,80 @@ describe('writeVarUInt', () => {
describe('1 byte', () => {
it('should read 0', () => {
const buffer = shouldWrite(0)
- expect(buffer.readUInt8()).toBe(0)
+ expect(buffer.readUInt8()).toStrictEqual(0)
})
it('should read 128', () => {
const buffer = shouldWrite(128)
- expect(buffer.readUInt8()).toBe(128)
+ expect(buffer.readUInt8()).toStrictEqual(128)
})
it('should read 252', () => {
const buffer = shouldWrite(252)
- expect(buffer.readUInt8()).toBe(252)
+ expect(buffer.readUInt8()).toStrictEqual(252)
})
})
describe('3 bytes', () => {
it('should read 253', () => {
const buffer = shouldWrite(253)
- expect(buffer.readUInt8()).toBe(0xfd)
- expect(buffer.readUInt16LE()).toBe(253)
+ expect(buffer.readUInt8()).toStrictEqual(0xfd)
+ expect(buffer.readUInt16LE()).toStrictEqual(253)
})
it('should read 25000', () => {
const buffer = shouldWrite(25000)
- expect(buffer.readUInt8()).toBe(0xfd)
- expect(buffer.readUInt16LE()).toBe(25000)
+ expect(buffer.readUInt8()).toStrictEqual(0xfd)
+ expect(buffer.readUInt16LE()).toStrictEqual(25000)
})
it('should read 65535', () => {
const buffer = shouldWrite(65535)
- expect(buffer.readUInt8()).toBe(0xfd)
- expect(buffer.readUInt16LE()).toBe(65535)
+ expect(buffer.readUInt8()).toStrictEqual(0xfd)
+ expect(buffer.readUInt16LE()).toStrictEqual(65535)
})
})
describe('5 bytes', () => {
it('should read 65536', () => {
const buffer = shouldWrite(65536)
- expect(buffer.readUInt8()).toBe(0xfe)
- expect(buffer.readUInt32LE()).toBe(65536)
+ expect(buffer.readUInt8()).toStrictEqual(0xfe)
+ expect(buffer.readUInt32LE()).toStrictEqual(65536)
})
it('should read 123456789', () => {
const buffer = shouldWrite(123456789)
- expect(buffer.readUInt8()).toBe(0xfe)
- expect(buffer.readUInt32LE()).toBe(123456789)
+ expect(buffer.readUInt8()).toStrictEqual(0xfe)
+ expect(buffer.readUInt32LE()).toStrictEqual(123456789)
})
it('should read 4294967295', () => {
const buffer = shouldWrite(4294967295)
- expect(buffer.readUInt8()).toBe(0xfe)
- expect(buffer.readUInt32LE()).toBe(4294967295)
+ expect(buffer.readUInt8()).toStrictEqual(0xfe)
+ expect(buffer.readUInt32LE()).toStrictEqual(4294967295)
})
})
describe('9 bytes', () => {
it('should read 4294967296', () => {
const buffer = shouldWrite(4294967296)
- expect(buffer.readUInt8()).toBe(0xff)
- expect(buffer.readUInt32LE()).toBe(4294967296 >>> 0)
- expect(buffer.readUInt32LE()).toBe((4294967296 / 0x100000000) | 0)
+ expect(buffer.readUInt8()).toStrictEqual(0xff)
+ expect(buffer.readUInt32LE()).toStrictEqual(4294967296 >>> 0)
+ expect(buffer.readUInt32LE()).toStrictEqual((4294967296 / 0x100000000) | 0)
})
it('should read 5234560000000000', () => {
const buffer = shouldWrite(5234560000000000)
- expect(buffer.readUInt8()).toBe(0xff)
- expect(buffer.readUInt32LE()).toBe(5234560000000000 >>> 0)
- expect(buffer.readUInt32LE()).toBe((5234560000000000 / 0x100000000) | 0)
+ expect(buffer.readUInt8()).toStrictEqual(0xff)
+ expect(buffer.readUInt32LE()).toStrictEqual(5234560000000000 >>> 0)
+ expect(buffer.readUInt32LE()).toStrictEqual((5234560000000000 / 0x100000000) | 0)
})
it('should read 9007199254740991', () => {
const buffer = shouldWrite(9007199254740991)
- expect(buffer.readUInt8()).toBe(0xff)
- expect(buffer.readUInt32LE()).toBe(9007199254740991 >>> 0)
- expect(buffer.readUInt32LE()).toBe((9007199254740991 / 0x100000000) | 0)
+ expect(buffer.readUInt8()).toStrictEqual(0xff)
+ expect(buffer.readUInt32LE()).toStrictEqual(9007199254740991 >>> 0)
+ expect(buffer.readUInt32LE()).toStrictEqual((9007199254740991 / 0x100000000) | 0)
})
})
})
@@ -107,7 +107,7 @@ describe('readVarUInt', () => {
function shouldRead (num: number, writer: (buffer: SmartBuffer) => void): void {
const buffer = new SmartBuffer()
writer(buffer)
- return expect(readVarUInt(buffer)).toBe(num)
+ return expect(readVarUInt(buffer)).toStrictEqual(num)
}
describe('1 byte', () => {
@@ -217,44 +217,44 @@ describe('readVarUInt', () => {
describe('byteLength', () => {
it('should be 1', () => {
- expect(byteLength(0)).toBe(1)
- expect(byteLength(1)).toBe(1)
- expect(byteLength(128)).toBe(1)
- expect(byteLength(252)).toBe(1)
- expect(byteLength(0xfc)).toBe(1)
+ expect(byteLength(0)).toStrictEqual(1)
+ expect(byteLength(1)).toStrictEqual(1)
+ expect(byteLength(128)).toStrictEqual(1)
+ expect(byteLength(252)).toStrictEqual(1)
+ expect(byteLength(0xfc)).toStrictEqual(1)
})
it('should be 3', () => {
- expect(byteLength(253)).toBe(3)
- expect(byteLength(1000)).toBe(3)
- expect(byteLength(10000)).toBe(3)
- expect(byteLength(65535)).toBe(3)
- expect(byteLength(0xffff)).toBe(3)
+ expect(byteLength(253)).toStrictEqual(3)
+ expect(byteLength(1000)).toStrictEqual(3)
+ expect(byteLength(10000)).toStrictEqual(3)
+ expect(byteLength(65535)).toStrictEqual(3)
+ expect(byteLength(0xffff)).toStrictEqual(3)
})
it('should be 5', () => {
- expect(byteLength(65536)).toBe(5)
- expect(byteLength(100000)).toBe(5)
- expect(byteLength(1200000)).toBe(5)
- expect(byteLength(12300000)).toBe(5)
- expect(byteLength(123400000)).toBe(5)
- expect(byteLength(1234500000)).toBe(5)
- expect(byteLength(4294967295)).toBe(5)
- expect(byteLength(0xffffffff)).toBe(5)
+ expect(byteLength(65536)).toStrictEqual(5)
+ expect(byteLength(100000)).toStrictEqual(5)
+ expect(byteLength(1200000)).toStrictEqual(5)
+ expect(byteLength(12300000)).toStrictEqual(5)
+ expect(byteLength(123400000)).toStrictEqual(5)
+ expect(byteLength(1234500000)).toStrictEqual(5)
+ expect(byteLength(4294967295)).toStrictEqual(5)
+ expect(byteLength(0xffffffff)).toStrictEqual(5)
})
it('should be 9', () => {
- expect(byteLength(4294967296)).toBe(9)
- expect(byteLength(10000000000)).toBe(9)
- expect(byteLength(120000000000)).toBe(9)
- expect(byteLength(1230000000000)).toBe(9)
- expect(byteLength(12340000000000)).toBe(9)
- expect(byteLength(123450000000000)).toBe(9)
- expect(byteLength(1234560000000000)).toBe(9)
- expect(byteLength(5234560000000000)).toBe(9)
- expect(byteLength(9007199254740991)).toBe(9)
- expect(byteLength(0x1fffffffffffff)).toBe(9)
- expect(byteLength(Number.MAX_SAFE_INTEGER)).toBe(9)
+ expect(byteLength(4294967296)).toStrictEqual(9)
+ expect(byteLength(10000000000)).toStrictEqual(9)
+ expect(byteLength(120000000000)).toStrictEqual(9)
+ expect(byteLength(1230000000000)).toStrictEqual(9)
+ expect(byteLength(12340000000000)).toStrictEqual(9)
+ expect(byteLength(123450000000000)).toStrictEqual(9)
+ expect(byteLength(1234560000000000)).toStrictEqual(9)
+ expect(byteLength(5234560000000000)).toStrictEqual(9)
+ expect(byteLength(9007199254740991)).toStrictEqual(9)
+ expect(byteLength(0x1fffffffffffff)).toStrictEqual(9)
+ expect(byteLength(Number.MAX_SAFE_INTEGER)).toStrictEqual(9)
})
it('should throw range error if out of Number.MAX_SAFE_INTEGER', () => {
diff --git a/packages/jellyfish-transaction/__tests__/index.test.ts b/packages/jellyfish-transaction/__tests__/index.test.ts
index 8dfee379a8..9f9011d790 100644
--- a/packages/jellyfish-transaction/__tests__/index.test.ts
+++ b/packages/jellyfish-transaction/__tests__/index.test.ts
@@ -44,5 +44,5 @@ it('should be able to use DeFiTransactionConstants constants to craft Transactio
const buffer = new SmartBuffer()
new CTransactionSegWit(data).toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toBe(hex)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
diff --git a/packages/jellyfish-transaction/__tests__/script/data.test.ts b/packages/jellyfish-transaction/__tests__/script/data.test.ts
index 2309805885..b04340829f 100644
--- a/packages/jellyfish-transaction/__tests__/script/data.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/data.test.ts
@@ -5,22 +5,22 @@ it('should construct as big endian', () => {
const buff = Buffer.from('00ff', 'hex')
const data = new OP_PUSHDATA(buff, 'big')
- expect(data.hex).toBe('ff00')
- expect(data.asBuffer().toString('hex')).toBe('02ff00')
+ expect(data.hex).toStrictEqual('ff00')
+ expect(data.asBuffer().toString('hex')).toStrictEqual('02ff00')
})
it('should construct as little endian', () => {
const buff = Buffer.from('00ff', 'hex')
const data = new OP_PUSHDATA(buff, 'little')
- expect(data.hex).toBe('00ff')
- expect(data.asBuffer().toString('hex')).toBe('0200ff')
+ expect(data.hex).toStrictEqual('00ff')
+ expect(data.asBuffer().toString('hex')).toStrictEqual('0200ff')
})
it('should return length of PUSHDATA', () => {
const buff = Buffer.from('00ff', 'hex')
const data = new OP_PUSHDATA(buff, 'little')
- expect(data.length()).toBe(2)
+ expect(data.length()).toStrictEqual(2)
})
describe('OP_PUSHDATA construct from buffer', () => {
@@ -28,9 +28,9 @@ describe('OP_PUSHDATA construct from buffer', () => {
const buff = Buffer.from(hex, 'hex')
const data = new OP_PUSHDATA(buff, 'little')
- expect(data.type).toBe('OP_PUSHDATA')
- expect(data.hex).toBe(hex)
- expect(data.asBuffer().toString('hex')).toBe(`${prefix}${hex}`)
+ expect(data.type).toStrictEqual('OP_PUSHDATA')
+ expect(data.hex).toStrictEqual(hex)
+ expect(data.asBuffer().toString('hex')).toStrictEqual(`${prefix}${hex}`)
}
it('1 len', () => {
@@ -70,9 +70,9 @@ describe('OP_PUSHDATA construct from code and smart buffer', () => {
const prefix = Buffer.allocUnsafe(1)
prefix.writeUInt8(code)
- expect(data.type).toBe('OP_PUSHDATA')
- expect(data.hex).toBe(hex)
- expect(data.asBuffer().toString('hex')).toBe(
+ expect(data.type).toStrictEqual('OP_PUSHDATA')
+ expect(data.hex).toStrictEqual(hex)
+ expect(data.asBuffer().toString('hex')).toStrictEqual(
`${prefix.toString('hex')}${len}${hex}`
)
}
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToAccount.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToAccount.test.ts
index 06997c0003..252a805ed2 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToAccount.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToAccount.test.ts
@@ -19,8 +19,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x42)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x42)
})
})
@@ -64,14 +64,14 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
it('should compose from buffer to composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CAccountToAccount(buffer)
- expect(composable.toObject()).toEqual(accountToAccount)
+ expect(composable.toObject()).toStrictEqual(accountToAccount)
})
it('should compose from composable to buffer', () => {
@@ -79,6 +79,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToUtxos.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToUtxos.test.ts
index c942e785d7..f9425df4c1 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToUtxos.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AccountToUtxos.test.ts
@@ -17,8 +17,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x62)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x62)
})
})
@@ -51,14 +51,14 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
it('should compose from buffer to composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CAccountToUtxos(buffer)
- expect(composable.toObject()).toEqual(accountToUtxos)
+ expect(composable.toObject()).toStrictEqual(accountToUtxos)
})
it('should compose from composable to buffer', () => {
@@ -66,6 +66,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AnyAccounToAccount.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AnyAccounToAccount.test.ts
index 5aa5ea4498..0a51137bc2 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AnyAccounToAccount.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/AnyAccounToAccount.test.ts
@@ -18,8 +18,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x61)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x61)
})
})
@@ -99,14 +99,14 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
it('should compose from buffer to composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CAnyAccountToAccount(buffer)
- expect(composable.toObject()).toEqual(anyAccountToAccount)
+ expect(composable.toObject()).toStrictEqual(anyAccountToAccount)
})
it('should compose from composable to buffer', () => {
@@ -114,6 +114,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/UtxosToAccount.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/UtxosToAccount.test.ts
index cf32bd9463..05bc0e7b9e 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/UtxosToAccount.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_account/UtxosToAccount.test.ts
@@ -24,8 +24,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x55)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x55)
})
})
@@ -55,14 +55,14 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
it('should compose from buffer to composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CUtxosToAccount(buffer)
- expect(composable.toObject()).toEqual(utxosToAccount)
+ expect(composable.toObject()).toStrictEqual(utxosToAccount)
})
it('should compose from composable to buffer', () => {
@@ -70,6 +70,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/ScriptBalances.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/ScriptBalances.test.ts
index a201ce80e2..2c3b5a74be 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/ScriptBalances.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/ScriptBalances.test.ts
@@ -23,13 +23,13 @@ describe('Composable', () => {
it('should compose from buffer to composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CScriptBalances(buffer)
- expect(composable.toObject()).toEqual(scriptBalances)
+ expect(composable.toObject()).toStrictEqual(scriptBalances)
})
it('should compose from composable to buffer', () => {
const composable = new CScriptBalances(scriptBalances)
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/TokenBalance.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/TokenBalance.test.ts
index ad8afc90d5..8458f1651f 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/TokenBalance.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_balance/TokenBalance.test.ts
@@ -12,13 +12,13 @@ describe('Composable', () => {
it('should compose from buffer to composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CTokenBalance(buffer)
- expect(composable.toObject()).toEqual(tokenBalance)
+ expect(composable.toObject()).toStrictEqual(tokenBalance)
})
it('should compose from composable to buffer', () => {
const composable = new CTokenBalance(tokenBalance)
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_misc/AutoAuthPrep.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_misc/AutoAuthPrep.test.ts
new file mode 100644
index 0000000000..599024b3ce
--- /dev/null
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_misc/AutoAuthPrep.test.ts
@@ -0,0 +1,53 @@
+import { SmartBuffer } from 'smart-buffer'
+import { OP_DEFI_TX } from '../../../../src/script/defi'
+import { OP_CODES } from '../../../../src'
+import { toBuffer, toOPCodes } from '../../../../src/script/_buffer'
+import { CAutoAuthPrep } from '../../../../src/script/defi/dftx_misc'
+
+it('should bi-directional buffer-object-buffer', () => {
+ // AutoAuthPrep literally has no data, only header
+ const fixtures = [
+ '6a054466547841'
+ ]
+
+ fixtures.forEach(hex => {
+ const stack = toOPCodes(
+ SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
+ )
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x41)
+ })
+})
+
+/**
+ * using autoAuthPrep sample from
+ * https://explorer.defichain.io/#/DFI/mainnet/tx/362266760fbe1743c9077dadac100cc98b122308bb063420dc32cea1dace755c
+ */
+const header = '6a054466547841' // OP_RETURN 44665478 41
+
+it('should craft dftx with OP_CODES._()', () => {
+ const stack = [
+ OP_CODES.OP_RETURN,
+ OP_CODES.OP_DEFI_TX_AUTO_AUTH_PREP()
+ ]
+
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toStrictEqual(header)
+})
+
+describe('Composable', () => {
+ // essentially do not require 2 tests
+ // no data needed, constructor accept no argument
+ it('should compose from buffer to composable', () => {
+ const composable = new CAutoAuthPrep()
+ expect(composable.toObject()).toStrictEqual({})
+ })
+
+ it('should compose from composable to buffer', () => {
+ const composable = new CAutoAuthPrep()
+ const buffer = new SmartBuffer()
+ composable.toBuffer(buffer)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual('') // no data
+ })
+})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/AppointOracle.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/AppointOracle.test.ts
new file mode 100644
index 0000000000..9f596a6928
--- /dev/null
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/AppointOracle.test.ts
@@ -0,0 +1,75 @@
+import { SmartBuffer } from 'smart-buffer'
+import {
+ CAppointOracle,
+ AppointOracle
+} from '../../../../src/script/defi/dftx_oracles'
+import { OP_CODES } from '../../../../src/script'
+import { toBuffer, toOPCodes } from '../../../../src/script/_buffer'
+import { OP_DEFI_TX } from '../../../../src/script/defi'
+
+it('should bi-directional buffer-object-buffer', () => {
+ const fixtures = [
+ '6a35446654786f1976a914c52fcb3c6dd28e530e5d162fee41f235bf7709cd88ac0102055445534c4103455552055445534c4103555344'
+ ]
+
+ fixtures.forEach(hex => {
+ const stack = toOPCodes(
+ SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
+ )
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x6f)
+ })
+})
+
+const header = '6a35446654786f' // OP_RETURN, PUSH_DATA(44665478, 6f)
+const data = '1976a914c52fcb3c6dd28e530e5d162fee41f235bf7709cd88ac0102055445534c4103455552055445534c4103555344'
+const appointOracle: AppointOracle = {
+ script: {
+ stack: [
+ OP_CODES.OP_DUP,
+ OP_CODES.OP_HASH160,
+ OP_CODES.OP_PUSHDATA_HEX_LE('c52fcb3c6dd28e530e5d162fee41f235bf7709cd'),
+ OP_CODES.OP_EQUALVERIFY,
+ OP_CODES.OP_CHECKSIG
+ ]
+ },
+ weightage: 1,
+ priceFeeds: [
+ {
+ token: 'TESLA',
+ currency: 'EUR'
+ },
+ {
+ token: 'TESLA',
+ currency: 'USD'
+ }
+ ]
+}
+
+it('should craft dftx with OP_CODES._()', () => {
+ const stack = [
+ OP_CODES.OP_RETURN,
+ OP_CODES.OP_DEFI_TX_APPOINT_ORACLE(appointOracle)
+ ]
+
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(header + data)
+})
+
+describe('Composable', () => {
+ it('should compose from buffer to composable', () => {
+ const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
+ const composable = new CAppointOracle(buffer)
+
+ expect(composable.toObject()).toEqual(appointOracle)
+ })
+
+ it('should compose from composable to buffer', () => {
+ const composable = new CAppointOracle(appointOracle)
+ const buffer = new SmartBuffer()
+ composable.toBuffer(buffer)
+
+ expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ })
+})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/RemoveOracle.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/RemoveOracle.test.ts
new file mode 100644
index 0000000000..a6e6bb01e3
--- /dev/null
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/RemoveOracle.test.ts
@@ -0,0 +1,56 @@
+import { SmartBuffer } from 'smart-buffer'
+import {
+ CRemoveOracle,
+ RemoveOracle
+} from '../../../../src/script/defi/dftx_oracles'
+import { OP_CODES } from '../../../../src/script'
+import { toBuffer, toOPCodes } from '../../../../src/script/_buffer'
+import { OP_DEFI_TX } from '../../../../src/script/defi'
+
+it('should bi-directional buffer-object-buffer', () => {
+ const fixtures = [
+ '6a254466547868061d35948925528b2025c4b84ea6f4899bab6efbcaf63776258186d7728424d1'
+ ]
+
+ fixtures.forEach(hex => {
+ const stack = toOPCodes(
+ SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
+ )
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x68)
+ })
+})
+
+const header = '6a254466547868' // OP_RETURN, PUSH_DATA(44665478, 68)
+const data = '061d35948925528b2025c4b84ea6f4899bab6efbcaf63776258186d7728424d1'
+const removeOracle: RemoveOracle = {
+ oracleId: 'd1248472d78681257637f6cafb6eab9b89f4a64eb8c425208b52258994351d06'
+}
+
+it('should craft dftx with OP_CODES._()', () => {
+ const stack = [
+ OP_CODES.OP_RETURN,
+ OP_CODES.OP_DEFI_TX_REMOVE_ORACLE(removeOracle)
+ ]
+
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(header + data)
+})
+
+describe('Composable', () => {
+ it('should compose from buffer to composable', () => {
+ const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
+ const composable = new CRemoveOracle(buffer)
+
+ expect(composable.toObject()).toEqual(removeOracle)
+ })
+
+ it('should compose from composable to buffer', () => {
+ const composable = new CRemoveOracle(removeOracle)
+ const buffer = new SmartBuffer()
+ composable.toBuffer(buffer)
+
+ expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ })
+})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/SetOracleData.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/SetOracleData.test.ts
new file mode 100644
index 0000000000..7781495015
--- /dev/null
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/SetOracleData.test.ts
@@ -0,0 +1,70 @@
+import { SmartBuffer } from 'smart-buffer'
+import {
+ SetOracleData,
+ CSetOracleData
+} from '../../../../src/script/defi/dftx_oracles'
+import BigNumber from 'bignumber.js'
+import { OP_CODES } from '../../../../src/script'
+import { toBuffer, toOPCodes } from '../../../../src/script/_buffer'
+import { OP_DEFI_TX } from '../../../../src/script/defi'
+
+it('should bi-directional buffer-object-buffer', () => {
+ const fixtures = [
+ '6a414466547879061d35948925528b2025c4b84ea6f4899bab6efbcaf63776258186d7728424d1bc29a7600000000001055445534c41010355534400e1f50500000000'
+ ]
+
+ fixtures.forEach(hex => {
+ const stack = toOPCodes(
+ SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
+ )
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x79)
+ })
+})
+
+const header = '6a414466547879' // OP_RETURN, PUSH_DATA(44665478, 79)
+const data = '061d35948925528b2025c4b84ea6f4899bab6efbcaf63776258186d7728424d1bc29a7600000000001055445534c41010355534400e1f50500000000'
+
+const setOracleData: SetOracleData = {
+ oracleId: 'd1248472d78681257637f6cafb6eab9b89f4a64eb8c425208b52258994351d06',
+ timestamp: new BigNumber('1621567932'),
+ tokens: [
+ {
+ token: 'TESLA',
+ prices: [
+ {
+ currency: 'USD',
+ amount: new BigNumber('1.0')
+ }
+ ]
+ }
+ ]
+}
+
+it('should craft dftx with OP_CODES._()', () => {
+ const stack = [
+ OP_CODES.OP_RETURN,
+ OP_CODES.OP_DEFI_TX_SET_ORACLE_DATA(setOracleData)
+ ]
+
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(header + data)
+})
+
+describe('Composable', () => {
+ it('should compose from buffer to composable', () => {
+ const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
+ const composable = new CSetOracleData(buffer)
+
+ expect(composable.toObject()).toEqual(setOracleData)
+ })
+
+ it('should compose from composable to buffer', () => {
+ const composable = new CSetOracleData(setOracleData)
+ const buffer = new SmartBuffer()
+ composable.toBuffer(buffer)
+
+ expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ })
+})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/UpdateOracle.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/UpdateOracle.test.ts
new file mode 100644
index 0000000000..d7fda1bfda
--- /dev/null
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_oracles/UpdateOracle.test.ts
@@ -0,0 +1,80 @@
+import { SmartBuffer } from 'smart-buffer'
+import {
+ CUpdateOracle,
+ UpdateOracle
+} from '../../../../src/script/defi/dftx_oracles'
+import { OP_CODES } from '../../../../src/script'
+import { toBuffer, toOPCodes } from '../../../../src/script/_buffer'
+import { OP_DEFI_TX } from '../../../../src/script/defi'
+
+it('should bi-directional buffer-object-buffer', () => {
+ const fixtures = [
+ '6a4c5f4466547874061d35948925528b2025c4b84ea6f4899bab6efbcaf63776258186d7728424d11976a914ad1eaafdd6edcf2260f28cb31e24117c240681ca88ac0503055445534c4103455552055445534c41034a5059055445534c4103555344'
+ ]
+
+ fixtures.forEach(hex => {
+ const stack = toOPCodes(
+ SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
+ )
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x74)
+ })
+})
+
+const header = '6a4c5f4466547874' // OP_RETURN, PUSH_DATA(5f44665478, 74)
+const data = '061d35948925528b2025c4b84ea6f4899bab6efbcaf63776258186d7728424d11976a914ad1eaafdd6edcf2260f28cb31e24117c240681ca88ac0503055445534c4103455552055445534c41034a5059055445534c4103555344'
+const updateOracle: UpdateOracle = {
+ script: {
+ stack: [
+ OP_CODES.OP_DUP,
+ OP_CODES.OP_HASH160,
+ OP_CODES.OP_PUSHDATA_HEX_LE('ad1eaafdd6edcf2260f28cb31e24117c240681ca'),
+ OP_CODES.OP_EQUALVERIFY,
+ OP_CODES.OP_CHECKSIG
+ ]
+ },
+ oracleId: 'd1248472d78681257637f6cafb6eab9b89f4a64eb8c425208b52258994351d06',
+ weightage: 5,
+ pricefeeds: [
+ {
+ token: 'TESLA',
+ currency: 'EUR'
+ },
+ {
+ token: 'TESLA',
+ currency: 'JPY'
+ },
+ {
+ token: 'TESLA',
+ currency: 'USD'
+ }
+ ]
+}
+
+it('should craft dftx with OP_CODES._()', () => {
+ const stack = [
+ OP_CODES.OP_RETURN,
+ OP_CODES.OP_DEFI_TX_UPDATE_ORACLE(updateOracle)
+ ]
+
+ const buffer = toBuffer(stack)
+ expect(buffer.toString('hex')).toBe(header + data)
+})
+
+describe('Composable', () => {
+ it('should compose from buffer to composable', () => {
+ const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
+ const composable = new CUpdateOracle(buffer)
+
+ expect(composable.toObject()).toEqual(updateOracle)
+ })
+
+ it('should compose from composable to buffer', () => {
+ const composable = new CUpdateOracle(updateOracle)
+ const buffer = new SmartBuffer()
+ composable.toBuffer(buffer)
+
+ expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ })
+})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolAddLiquidity.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolAddLiquidity.test.ts
index ae7d1898d1..859cae4b52 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolAddLiquidity.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolAddLiquidity.test.ts
@@ -20,8 +20,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x6c)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x6c)
})
})
@@ -61,7 +61,7 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
@@ -69,7 +69,7 @@ describe('Composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CPoolAddLiquidity(buffer)
- expect(composable.toObject()).toEqual(poolAddLiquidity)
+ expect(composable.toObject()).toStrictEqual(poolAddLiquidity)
})
it('should compose from composable to buffer', () => {
@@ -77,6 +77,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolRemoveLiquidity.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolRemoveLiquidity.test.ts
index 779d47a4cc..ad80d7dbeb 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolRemoveLiquidity.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolRemoveLiquidity.test.ts
@@ -24,8 +24,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x72)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x72)
})
})
@@ -52,7 +52,7 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
@@ -60,7 +60,7 @@ describe('Composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CPoolRemoveLiquidity(buffer)
- expect(composable.toObject()).toEqual(poolRemoveLiquidity)
+ expect(composable.toObject()).toStrictEqual(poolRemoveLiquidity)
})
it('should compose from composable to buffer', () => {
@@ -68,6 +68,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolSwap.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolSwap.test.ts
index 802e392811..2962f9f23f 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolSwap.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_pool/PoolSwap.test.ts
@@ -23,8 +23,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x73)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x73)
})
})
@@ -61,7 +61,7 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
@@ -69,7 +69,7 @@ describe('Composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CPoolSwap(buffer)
- expect(composable.toObject()).toEqual(poolSwap)
+ expect(composable.toObject()).toStrictEqual(poolSwap)
})
it('should compose from composable to buffer', () => {
@@ -77,6 +77,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_token/TokenMint.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_token/TokenMint.test.ts
index 782c26f563..2e5e7d2998 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_token/TokenMint.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_token/TokenMint.test.ts
@@ -16,8 +16,8 @@ it('should bi-directional buffer-object-buffer', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
- expect((stack[1] as OP_DEFI_TX).tx.type).toBe(0x4d)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
+ expect((stack[1] as OP_DEFI_TX).tx.type).toStrictEqual(0x4d)
})
})
@@ -39,7 +39,7 @@ it('should craft dftx with OP_CODES._()', () => {
]
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(header + data)
+ expect(buffer.toString('hex')).toStrictEqual(header + data)
})
describe('Composable', () => {
@@ -47,7 +47,7 @@ describe('Composable', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(data, 'hex'))
const composable = new CTokenMint(buffer)
- expect(composable.toObject()).toEqual(tokenMint)
+ expect(composable.toObject()).toStrictEqual(tokenMint)
})
it('should compose from composable to buffer', () => {
@@ -55,6 +55,6 @@ describe('Composable', () => {
const buffer = new SmartBuffer()
composable.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toEqual(data)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(data)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/defi/dftx_unmapped.test.ts b/packages/jellyfish-transaction/__tests__/script/defi/dftx_unmapped.test.ts
index 723ccc2a58..58a41b1f72 100644
--- a/packages/jellyfish-transaction/__tests__/script/defi/dftx_unmapped.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/defi/dftx_unmapped.test.ts
@@ -11,7 +11,7 @@ it('should bi-directional map unmapped buffer-object-buffer', () => {
)
const buffer = toBuffer(stack)
- expect(buffer.toString('hex')).toBe(hex)
+ expect(buffer.toString('hex')).toStrictEqual(hex)
})
it('should map as mapped if it is unmapped', () => {
@@ -21,14 +21,14 @@ it('should map as mapped if it is unmapped', () => {
SmartBuffer.fromBuffer(Buffer.from(hex, 'hex'))
)
- expect(stack[0].type).toBe('OP_RETURN')
- expect(stack[1].type).toBe('OP_DEFI_TX')
+ expect(stack[0].type).toStrictEqual('OP_RETURN')
+ expect(stack[1].type).toStrictEqual('OP_DEFI_TX')
const tx = (stack[1] as OP_DEFI_TX).tx
- expect(tx.signature).toBe(1147556984)
- expect(tx.type).toBe(0)
- expect(tx.name).toBe('OP_DEFI_TX_UNMAPPED')
+ expect(tx.signature).toStrictEqual(1147556984)
+ expect(tx.type).toStrictEqual(0)
+ expect(tx.name).toStrictEqual('OP_DEFI_TX_UNMAPPED')
const unmapped = tx.data as DeFiOpUnmapped
- expect(unmapped.hex).toBe('001234')
+ expect(unmapped.hex).toStrictEqual('001234')
})
diff --git a/packages/jellyfish-transaction/__tests__/script/index.test.ts b/packages/jellyfish-transaction/__tests__/script/index.test.ts
index 7db30d00b1..9634268faa 100644
--- a/packages/jellyfish-transaction/__tests__/script/index.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/index.test.ts
@@ -8,13 +8,13 @@ describe('[]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes.length).toBe(0)
+ expect(codes.length).toStrictEqual(0)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -25,14 +25,14 @@ describe('[OP_0]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_0')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_0')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_0], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -43,14 +43,14 @@ describe('[OP_1NEGATE]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_1NEGATE')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_1NEGATE')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_1NEGATE], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -61,14 +61,14 @@ describe('[OP_RESERVED]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_RESERVED')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_RESERVED')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_RESERVED], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -79,14 +79,14 @@ describe('[OP_1]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_1')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_1')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_1], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -97,14 +97,14 @@ describe('[OP_2]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_2')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_2')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_2], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -115,14 +115,14 @@ describe('[OP_3]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_3')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_3')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_3], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -133,14 +133,14 @@ describe('[OP_4]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_4')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_4')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_4], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -151,14 +151,14 @@ describe('[OP_5]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_5')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_5')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_5], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -169,14 +169,14 @@ describe('[OP_6]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_6')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_6')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_6], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -187,14 +187,14 @@ describe('[OP_7]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_7')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_7')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_7], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -205,14 +205,14 @@ describe('[OP_8]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_8')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_8')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_8], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -223,14 +223,14 @@ describe('[OP_9]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_9')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_9')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_9], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -241,14 +241,14 @@ describe('[OP_10]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_10')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_10')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_10], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -259,14 +259,14 @@ describe('[OP_11]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_11')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_11')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_11], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -277,14 +277,14 @@ describe('[OP_12]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_12')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_12')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_12], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -295,14 +295,14 @@ describe('[OP_13]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_13')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_13')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_13], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -313,14 +313,14 @@ describe('[OP_14]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_14')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_14')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_14], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -331,14 +331,14 @@ describe('[OP_15]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_15')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_15')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_15], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -349,14 +349,14 @@ describe('[OP_16]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_16')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_16')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_16], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -367,14 +367,14 @@ describe('[OP_RETURN]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_RETURN')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_RETURN')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_RETURN], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -385,14 +385,14 @@ describe('[OP_RIPEMD160]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_RIPEMD160')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_RIPEMD160')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_RIPEMD160], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -403,14 +403,14 @@ describe('[OP_SHA1]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_SHA1')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_SHA1')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_SHA1], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -421,14 +421,14 @@ describe('[OP_SHA256]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_SHA256')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_SHA256')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_SHA256], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -439,14 +439,14 @@ describe('[OP_HASH160]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_HASH160')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_HASH160')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_HASH160], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -457,14 +457,14 @@ describe('[OP_HASH256]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_HASH256')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_HASH256')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_HASH256], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -475,14 +475,14 @@ describe('[OP_CODESEPARATOR]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_CODESEPARATOR')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_CODESEPARATOR')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_CODESEPARATOR], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -493,14 +493,14 @@ describe('[OP_CHECKSIG]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_CHECKSIG')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_CHECKSIG')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_CHECKSIG], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -511,14 +511,14 @@ describe('[OP_CHECKSIGVERIFY]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_CHECKSIGVERIFY')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_CHECKSIGVERIFY')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_CHECKSIGVERIFY], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -529,14 +529,14 @@ describe('[OP_CHECKMULTISIG]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_CHECKMULTISIG')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_CHECKMULTISIG')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_CHECKMULTISIG], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -547,14 +547,14 @@ describe('[OP_CHECKMULTISIGVERIFY]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_CHECKMULTISIGVERIFY')
- expect(codes.length).toBe(1)
+ expect(codes[0].type).toStrictEqual('OP_CHECKMULTISIGVERIFY')
+ expect(codes.length).toStrictEqual(1)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_CHECKMULTISIGVERIFY], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -565,15 +565,15 @@ describe('[OP_RETURN, OP_0]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_RETURN')
- expect(codes[1].type).toBe('OP_0')
- expect(codes.length).toBe(2)
+ expect(codes[0].type).toStrictEqual('OP_RETURN')
+ expect(codes[1].type).toStrictEqual('OP_0')
+ expect(codes.length).toStrictEqual(2)
})
it('should map toBuffer', () => {
const smartBuffer = new SmartBuffer()
OP_CODES.toBuffer([OP_CODES.OP_RETURN, OP_CODES.OP_0], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -585,10 +585,10 @@ describe('[OP_RETURN, OP_PUSHDATA, OP_0]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes[0].type).toBe('OP_RETURN')
- expect((codes[1] as OP_PUSHDATA).hex).toBe(pushData)
- expect(codes[2].type).toBe('OP_0')
- expect(codes.length).toBe(3)
+ expect(codes[0].type).toStrictEqual('OP_RETURN')
+ expect((codes[1] as OP_PUSHDATA).hex).toStrictEqual(pushData)
+ expect(codes[2].type).toStrictEqual('OP_0')
+ expect(codes.length).toStrictEqual(3)
})
it('should map toBuffer', () => {
@@ -598,7 +598,7 @@ describe('[OP_RETURN, OP_PUSHDATA, OP_0]', () => {
new OP_PUSHDATA(Buffer.from(pushData, 'hex'), 'little'),
OP_CODES.OP_0
], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -610,9 +610,9 @@ describe('[OP_PUSHDATA, OP_0]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect((codes[0] as OP_PUSHDATA).hex).toBe(pushData)
- expect(codes[1].type).toBe('OP_0')
- expect(codes.length).toBe(2)
+ expect((codes[0] as OP_PUSHDATA).hex).toStrictEqual(pushData)
+ expect(codes[1].type).toStrictEqual('OP_0')
+ expect(codes.length).toStrictEqual(2)
})
it('should map toBuffer', () => {
@@ -621,7 +621,7 @@ describe('[OP_PUSHDATA, OP_0]', () => {
new OP_PUSHDATA(Buffer.from(pushData, 'hex'), 'little'),
OP_CODES.OP_0
], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -633,12 +633,12 @@ describe('P2PKH: [OP_DUP, OP_HASH160, OP_PUSHDATA, OP
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes.length).toBe(5)
- expect(codes[0].type).toBe('OP_DUP')
- expect(codes[1].type).toBe('OP_HASH160')
- expect((codes[2] as OP_PUSHDATA).hex).toBe(pushData)
- expect(codes[3].type).toBe('OP_EQUALVERIFY')
- expect(codes[4].type).toBe('OP_CHECKSIG')
+ expect(codes.length).toStrictEqual(5)
+ expect(codes[0].type).toStrictEqual('OP_DUP')
+ expect(codes[1].type).toStrictEqual('OP_HASH160')
+ expect((codes[2] as OP_PUSHDATA).hex).toStrictEqual(pushData)
+ expect(codes[3].type).toStrictEqual('OP_EQUALVERIFY')
+ expect(codes[4].type).toStrictEqual('OP_CHECKSIG')
})
it('should map toBuffer', () => {
@@ -650,7 +650,7 @@ describe('P2PKH: [OP_DUP, OP_HASH160, OP_PUSHDATA, OP
OP_CODES.OP_EQUALVERIFY,
OP_CODES.OP_CHECKSIG
], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -662,10 +662,10 @@ describe('P2SH: [OP_HASH160, OP_PUSHDATA, OP_EQUAL]',
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes.length).toBe(3)
- expect(codes[0].type).toBe('OP_HASH160')
- expect((codes[1] as OP_PUSHDATA).hex).toBe(pushData)
- expect(codes[2].type).toBe('OP_EQUAL')
+ expect(codes.length).toStrictEqual(3)
+ expect(codes[0].type).toStrictEqual('OP_HASH160')
+ expect((codes[1] as OP_PUSHDATA).hex).toStrictEqual(pushData)
+ expect(codes[2].type).toStrictEqual('OP_EQUAL')
})
it('should map toBuffer', () => {
@@ -675,7 +675,7 @@ describe('P2SH: [OP_HASH160, OP_PUSHDATA, OP_EQUAL]',
new OP_PUSHDATA(Buffer.from(pushData, 'hex'), 'little'),
OP_CODES.OP_EQUAL
], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -687,9 +687,9 @@ describe('P2WPKH: [OP_0, OP_PUSHDATA]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes.length).toBe(2)
- expect(codes[0].type).toBe('OP_0')
- expect((codes[1] as OP_PUSHDATA).hex).toBe(pushData)
+ expect(codes.length).toStrictEqual(2)
+ expect(codes[0].type).toStrictEqual('OP_0')
+ expect((codes[1] as OP_PUSHDATA).hex).toStrictEqual(pushData)
})
it('should map toBuffer', () => {
@@ -698,7 +698,7 @@ describe('P2WPKH: [OP_0, OP_PUSHDATA]', () => {
OP_CODES.OP_0,
new OP_PUSHDATA(Buffer.from(pushData, 'hex'), 'little')
], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
@@ -710,10 +710,10 @@ describe('P2WSH: [OP_0, OP_PUSHDATA]', () => {
const codes = OP_CODES.fromBuffer(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(codes.length).toBe(2)
- expect(codes[0].type).toBe('OP_0')
- expect((codes[1] as OP_PUSHDATA).hex.length).toBe(64)
- expect((codes[1] as OP_PUSHDATA).hex).toBe(pushData)
+ expect(codes.length).toStrictEqual(2)
+ expect(codes[0].type).toStrictEqual('OP_0')
+ expect((codes[1] as OP_PUSHDATA).hex.length).toStrictEqual(64)
+ expect((codes[1] as OP_PUSHDATA).hex).toStrictEqual(pushData)
})
it('should map toBuffer', () => {
@@ -722,6 +722,6 @@ describe('P2WSH: [OP_0, OP_PUSHDATA]', () => {
OP_CODES.OP_0,
new OP_PUSHDATA(Buffer.from(pushData, 'hex'), 'little')
], smartBuffer)
- expect(smartBuffer.toBuffer().toString('hex')).toBe(hex)
+ expect(smartBuffer.toBuffer().toString('hex')).toStrictEqual(hex)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/script/mapping.test.ts b/packages/jellyfish-transaction/__tests__/script/mapping.test.ts
index 751e0cd3e4..766033b415 100644
--- a/packages/jellyfish-transaction/__tests__/script/mapping.test.ts
+++ b/packages/jellyfish-transaction/__tests__/script/mapping.test.ts
@@ -2,16 +2,16 @@ import * as script from '../../src/script'
it('OP_UNMAPPED', () => {
expect(script.numAsOPCode(0xfe)).toBeInstanceOf(script.OP_UNMAPPED)
- expect(script.numAsOPCode(0xfe).type).toBe('OP_UNMAPPED_CODE_254')
- expect(script.numAsOPCode(0xfe).asBuffer().toString('hex')).toBe('fe')
+ expect(script.numAsOPCode(0xfe).type).toStrictEqual('OP_UNMAPPED_CODE_254')
+ expect(script.numAsOPCode(0xfe).asBuffer().toString('hex')).toStrictEqual('fe')
})
describe('All mapped OP_CODES are setup properly: (static, hex, num, asm)', () => {
function expectOPCode (code: script.StaticCode, instanceOf: any, type: string, num: number, hex: string): void {
expect(code).toBeInstanceOf(instanceOf)
expect(script.numAsOPCode(num)).toBeInstanceOf(instanceOf)
- expect(code.type).toBe(type)
- expect(code.asBuffer().toString('hex')).toBe(hex)
+ expect(code.type).toStrictEqual(type)
+ expect(code.asBuffer().toString('hex')).toStrictEqual(hex)
}
it('OP_0', () => {
diff --git a/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_1.test.ts b/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_1.test.ts
index 77a5d30f99..4b744cd82c 100644
--- a/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_1.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_1.test.ts
@@ -18,7 +18,7 @@ it('bi-directional unsigned buffer', () => {
const toBuffer = new SmartBuffer()
tx.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(unsigned)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(unsigned)
})
it('bi-directional signed buffer', () => {
@@ -28,7 +28,7 @@ it('bi-directional signed buffer', () => {
const toBuffer = new SmartBuffer()
tx.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(signed)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(signed)
})
it('sign transaction', async () => {
@@ -54,5 +54,5 @@ it('sign transaction', async () => {
const toBuffer = new SmartBuffer()
txSigned.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(signed)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(signed)
})
diff --git a/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_2.test.ts b/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_2.test.ts
index 1e68689e94..9759213a5c 100644
--- a/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_2.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx/p2wpkh_1_to_2.test.ts
@@ -18,7 +18,7 @@ it('bi-directional unsigned buffer', () => {
const toBuffer = new SmartBuffer()
tx.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(unsigned)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(unsigned)
})
it('bi-directional signed buffer', () => {
@@ -28,7 +28,7 @@ it('bi-directional signed buffer', () => {
const toBuffer = new SmartBuffer()
tx.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(signed)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(signed)
})
it('sign transaction', async () => {
@@ -54,5 +54,5 @@ it('sign transaction', async () => {
const toBuffer = new SmartBuffer()
txSigned.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(signed)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(signed)
})
diff --git a/packages/jellyfish-transaction/__tests__/tx_composer/CTransaction.test.ts b/packages/jellyfish-transaction/__tests__/tx_composer/CTransaction.test.ts
index 963587160e..88fb435ee9 100644
--- a/packages/jellyfish-transaction/__tests__/tx_composer/CTransaction.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_composer/CTransaction.test.ts
@@ -35,19 +35,19 @@ describe('CTransaction', () => {
}
const transaction = new CTransaction(data)
- expect(transaction.version).toBe(data.version)
+ expect(transaction.version).toStrictEqual(data.version)
- expect(transaction.vin.length).toBe(data.vin.length)
- expect(transaction.vin[0].txid).toBe(data.vin[0].txid)
- expect(transaction.vin[0].index).toBe(data.vin[0].index)
- expect(transaction.vin[0].script.stack).toBe(data.vin[0].script.stack)
- expect(transaction.vin[0].sequence).toBe(data.vin[0].sequence)
+ expect(transaction.vin.length).toStrictEqual(data.vin.length)
+ expect(transaction.vin[0].txid).toStrictEqual(data.vin[0].txid)
+ expect(transaction.vin[0].index).toStrictEqual(data.vin[0].index)
+ expect(transaction.vin[0].script.stack).toStrictEqual(data.vin[0].script.stack)
+ expect(transaction.vin[0].sequence).toStrictEqual(data.vin[0].sequence)
- expect(transaction.vout.length).toBe(data.vout.length)
- expect(transaction.vout[0].value).toBe(data.vout[0].value)
- expect(transaction.vout[0].script.stack).toBe(data.vout[0].script.stack)
+ expect(transaction.vout.length).toStrictEqual(data.vout.length)
+ expect(transaction.vout[0].value).toStrictEqual(data.vout[0].value)
+ expect(transaction.vout[0].script.stack).toStrictEqual(data.vout[0].script.stack)
- expect(transaction.lockTime).toBe(data.lockTime)
+ expect(transaction.lockTime).toStrictEqual(data.lockTime)
})
describe('P2WPKH (UNSIGNED)', () => {
diff --git a/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionSegWit.test.ts b/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionSegWit.test.ts
index 15473d65ac..3fbbc9bc22 100644
--- a/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionSegWit.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionSegWit.test.ts
@@ -44,24 +44,24 @@ describe('CTransactionSegWit', () => {
}
const segWit = new CTransactionSegWit(data)
- expect(segWit.version).toBe(data.version)
- expect(segWit.marker).toBe(data.marker)
- expect(segWit.flag).toBe(data.flag)
+ expect(segWit.version).toStrictEqual(data.version)
+ expect(segWit.marker).toStrictEqual(data.marker)
+ expect(segWit.flag).toStrictEqual(data.flag)
- expect(segWit.vin.length).toBe(data.vin.length)
- expect(segWit.vin[0].txid).toBe(data.vin[0].txid)
- expect(segWit.vin[0].index).toBe(data.vin[0].index)
- expect(segWit.vin[0].script.stack.length).toBe(data.vin[0].script.stack.length)
- expect(segWit.vin[0].sequence).toBe(data.vin[0].sequence)
+ expect(segWit.vin.length).toStrictEqual(data.vin.length)
+ expect(segWit.vin[0].txid).toStrictEqual(data.vin[0].txid)
+ expect(segWit.vin[0].index).toStrictEqual(data.vin[0].index)
+ expect(segWit.vin[0].script.stack.length).toStrictEqual(data.vin[0].script.stack.length)
+ expect(segWit.vin[0].sequence).toStrictEqual(data.vin[0].sequence)
- expect(segWit.vout.length).toBe(data.vout.length)
- expect(segWit.vout[0].value).toBe(data.vout[0].value)
- expect(segWit.vout[0].script.stack.length).toBe(data.vout[0].script.stack.length)
+ expect(segWit.vout.length).toStrictEqual(data.vout.length)
+ expect(segWit.vout[0].value).toStrictEqual(data.vout[0].value)
+ expect(segWit.vout[0].script.stack.length).toStrictEqual(data.vout[0].script.stack.length)
- expect(segWit.witness.length).toBe(data.witness.length)
- expect(segWit.witness[0].scripts.length).toBe(data.witness[0].scripts.length)
+ expect(segWit.witness.length).toStrictEqual(data.witness.length)
+ expect(segWit.witness[0].scripts.length).toStrictEqual(data.witness[0].scripts.length)
- expect(segWit.lockTime).toBe(data.lockTime)
+ expect(segWit.lockTime).toStrictEqual(data.lockTime)
})
describe('P2WPKH (SIGNED)', () => {
diff --git a/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionV2.test.ts b/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionV2.test.ts
index 822ded277c..b2c9c0b866 100644
--- a/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionV2.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_composer/CTransactionV2.test.ts
@@ -8,12 +8,12 @@ describe('Transaction', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(v2, 'hex'))
const composable = new CTransaction(buffer)
- expect(composable.vin[0].txid).toBe('0000000000000000000000000000000000000000000000000000000000000000')
- expect(composable.vout.length).toBe(3)
+ expect(composable.vin[0].txid).toStrictEqual('0000000000000000000000000000000000000000000000000000000000000000')
+ expect(composable.vout.length).toStrictEqual(3)
expect(composable.vout[0].tokenId).toBeUndefined()
- expect(composable.vout[0].value.toString()).toBe('194.99933826')
- expect(composable.vout[0].script.stack.length).toBe(5)
+ expect(composable.vout[0].value.toString()).toStrictEqual('194.99933826')
+ expect(composable.vout[0].script.stack.length).toStrictEqual(5)
})
it('should bi-directional buffer to object to buffer', () => {
@@ -26,7 +26,7 @@ describe('Transaction', () => {
const toBuffer = new SmartBuffer()
txn.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(v2)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(v2)
})
})
@@ -37,12 +37,12 @@ describe('TransactionSegWit', () => {
const buffer = SmartBuffer.fromBuffer(Buffer.from(v2, 'hex'))
const composable = new CTransactionSegWit(buffer)
- expect(composable.vin.length).toBe(1)
+ expect(composable.vin.length).toStrictEqual(1)
- expect(composable.vout.length).toBe(3)
+ expect(composable.vout.length).toStrictEqual(3)
expect(composable.vout[0].tokenId).toBeUndefined()
- expect(composable.vout[0].value.toString()).toBe('194.99933826')
- expect(composable.vout[0].script.stack.length).toBe(5)
+ expect(composable.vout[0].value.toString()).toStrictEqual('194.99933826')
+ expect(composable.vout[0].script.stack.length).toStrictEqual(5)
})
it('should bi-directional buffer to object to buffer', () => {
@@ -55,6 +55,6 @@ describe('TransactionSegWit', () => {
const toBuffer = new SmartBuffer()
txn.toBuffer(toBuffer)
- expect(toBuffer.toBuffer().toString('hex')).toBe(v2)
+ expect(toBuffer.toBuffer().toString('hex')).toStrictEqual(v2)
})
})
diff --git a/packages/jellyfish-transaction/__tests__/tx_composer/CVout.test.ts b/packages/jellyfish-transaction/__tests__/tx_composer/CVout.test.ts
index b287a74b16..8b8da5805d 100644
--- a/packages/jellyfish-transaction/__tests__/tx_composer/CVout.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_composer/CVout.test.ts
@@ -177,7 +177,7 @@ describe('CVoutV4', () => {
const composable = new CVoutV2(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(composable.value).toEqual(data.value)
+ expect(composable.value).toStrictEqual(data.value)
})
it('should compose from Object to Composable to Buffer', () => {
@@ -202,7 +202,7 @@ describe('CVoutV4', () => {
const composable = new CVoutV2(SmartBuffer.fromBuffer(
Buffer.from(hex, 'hex')
))
- expect(composable.value).toEqual(data.value)
+ expect(composable.value).toStrictEqual(data.value)
})
it('should compose from Object to Composable to Buffer', () => {
diff --git a/packages/jellyfish-transaction/__tests__/tx_composer/index.ts b/packages/jellyfish-transaction/__tests__/tx_composer/index.ts
index 713a341422..b70eb911a4 100644
--- a/packages/jellyfish-transaction/__tests__/tx_composer/index.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_composer/index.ts
@@ -6,9 +6,9 @@ export function expectHexBufferToObject (hex: string, data: T, asC: ((buffer:
Buffer.from(hex, 'hex')
))
- expect(composable.toObject()).toEqual(data)
+ expect(composable.toObject()).toStrictEqual(data)
// parse and stringify due to JSON path inconsistent positioning
- expect(JSON.parse(JSON.stringify(composable.toObject()))).toEqual(
+ expect(JSON.parse(JSON.stringify(composable.toObject()))).toStrictEqual(
JSON.parse(JSON.stringify(data))
)
}
@@ -19,9 +19,9 @@ export function expectObjectToHexBuffer (data: T, hex: string, asC: ((data: T
const buffer = new SmartBuffer()
txn.toBuffer(buffer)
- expect(buffer.toBuffer().toString('hex')).toBe(hex)
+ expect(buffer.toBuffer().toString('hex')).toStrictEqual(hex)
// parse and stringify due to JSON path inconsistent positioning
- expect(JSON.parse(JSON.stringify(txn.toObject()))).toEqual(
+ expect(JSON.parse(JSON.stringify(txn.toObject()))).toStrictEqual(
JSON.parse(JSON.stringify(data))
)
}
diff --git a/packages/jellyfish-transaction/__tests__/tx_signature/sign_input.test.ts b/packages/jellyfish-transaction/__tests__/tx_signature/sign_input.test.ts
index 06bc74824d..0c7f8bc2f8 100644
--- a/packages/jellyfish-transaction/__tests__/tx_signature/sign_input.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_signature/sign_input.test.ts
@@ -75,11 +75,11 @@ describe('sign single input', () => {
ellipticPair: keyPair
}, SIGHASH.ALL)
- expect(witness.scripts.length).toBe(2)
- expect(witness.scripts[0].hex).toBe(
+ expect(witness.scripts.length).toStrictEqual(2)
+ expect(witness.scripts[0].hex).toStrictEqual(
'30440220529a7ad524c004d68dc331cc2a5c339051da00d73c49cca28661eb1e44f73ad002200ac99a3fec7030528839ac33f7870c462d542d57662ae3f79966a997a0e9115a01'
)
- expect(witness.scripts[1].hex).toBe(
+ expect(witness.scripts[1].hex).toStrictEqual(
'025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357'
)
})
@@ -99,11 +99,11 @@ describe('sign single input', () => {
}
}, SIGHASH.ALL)
- expect(witness.scripts.length).toBe(2)
- expect(witness.scripts[0].hex).toBe(
+ expect(witness.scripts.length).toStrictEqual(2)
+ expect(witness.scripts[0].hex).toStrictEqual(
'30440220529a7ad524c004d68dc331cc2a5c339051da00d73c49cca28661eb1e44f73ad002200ac99a3fec7030528839ac33f7870c462d542d57662ae3f79966a997a0e9115a01'
)
- expect(witness.scripts[1].hex).toBe(
+ expect(witness.scripts[1].hex).toStrictEqual(
'025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357'
)
})
@@ -123,11 +123,11 @@ describe('sign single input', () => {
}
}, SIGHASH.ALL)
- expect(witness.scripts.length).toBe(2)
- expect(witness.scripts[0].hex).not.toBe(
+ expect(witness.scripts.length).toStrictEqual(2)
+ expect(witness.scripts[0].hex).not.toStrictEqual(
'304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee01'
)
- expect(witness.scripts[1].hex).toBe(
+ expect(witness.scripts[1].hex).toStrictEqual(
'025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357'
)
})
diff --git a/packages/jellyfish-transaction/__tests__/tx_signature/sign_transaction.test.ts b/packages/jellyfish-transaction/__tests__/tx_signature/sign_transaction.test.ts
index 9bf2619593..2136031923 100644
--- a/packages/jellyfish-transaction/__tests__/tx_signature/sign_transaction.test.ts
+++ b/packages/jellyfish-transaction/__tests__/tx_signature/sign_transaction.test.ts
@@ -55,17 +55,17 @@ describe('sign transaction', () => {
ellipticPair: keyPair
}])
- expect(signed.version).toBe(DeFiTransactionConstants.Version)
- expect(signed.marker).toBe(DeFiTransactionConstants.WitnessMarker)
- expect(signed.flag).toBe(DeFiTransactionConstants.WitnessFlag)
+ expect(signed.version).toStrictEqual(DeFiTransactionConstants.Version)
+ expect(signed.marker).toStrictEqual(DeFiTransactionConstants.WitnessMarker)
+ expect(signed.flag).toStrictEqual(DeFiTransactionConstants.WitnessFlag)
- expect(signed.vin.length).toBe(1)
- expect(signed.vout.length).toBe(1)
+ expect(signed.vin.length).toStrictEqual(1)
+ expect(signed.vout.length).toStrictEqual(1)
- expect(signed.witness.length).toBe(1)
- expect(signed.witness[0].scripts.length).toBe(2)
+ expect(signed.witness.length).toStrictEqual(1)
+ expect(signed.witness[0].scripts.length).toStrictEqual(2)
- expect(signed.lockTime).toBe(0x00000000)
+ expect(signed.lockTime).toStrictEqual(0x00000000)
})
describe('validation', () => {
@@ -120,7 +120,7 @@ describe('sign transaction', () => {
version: false
}
})
- expect(signed.version).toBe(1)
+ expect(signed.version).toStrictEqual(1)
})
it('should fail if lockTime is not set to 0', async () => {
@@ -142,7 +142,7 @@ describe('sign transaction', () => {
lockTime: false
}
})
- expect(signed.lockTime).toBe(1000)
+ expect(signed.lockTime).toStrictEqual(1000)
})
})
diff --git a/packages/jellyfish-transaction/src/script/defi/dftx.ts b/packages/jellyfish-transaction/src/script/defi/dftx.ts
index 8f4df1b5ee..ce6e0f58d4 100644
--- a/packages/jellyfish-transaction/src/script/defi/dftx.ts
+++ b/packages/jellyfish-transaction/src/script/defi/dftx.ts
@@ -10,11 +10,22 @@ import {
CUtxosToAccount,
UtxosToAccount
} from './dftx_account'
+import { CAutoAuthPrep } from './dftx_misc'
import {
CPoolAddLiquidity, CPoolRemoveLiquidity, CPoolSwap, PoolAddLiquidity, PoolRemoveLiquidity,
PoolSwap
} from './dftx_pool'
import { CTokenCreate, CTokenMint, TokenCreate, TokenMint } from './dftx_token'
+import {
+ CAppointOracle,
+ AppointOracle,
+ CUpdateOracle,
+ UpdateOracle,
+ CRemoveOracle,
+ RemoveOracle,
+ CSetOracleData,
+ SetOracleData
+} from './dftx_oracles'
import { CDeFiOpUnmapped, DeFiOpUnmapped } from './dftx_unmapped'
// Disabling no-return-assign makes the code cleaner with the setter and getter */
@@ -110,6 +121,16 @@ export class CDfTx extends ComposableBuffer> {
return compose(CAccountToAccount.OP_NAME, d => new CAccountToAccount(d))
case CAnyAccountToAccount.OP_CODE:
return compose(CAnyAccountToAccount.OP_NAME, d => new CAnyAccountToAccount(d))
+ case CAppointOracle.OP_CODE:
+ return compose(CAppointOracle.OP_NAME, d => new CAppointOracle(d))
+ case CRemoveOracle.OP_CODE:
+ return compose(CRemoveOracle.OP_NAME, d => new CRemoveOracle(d))
+ case CUpdateOracle.OP_CODE:
+ return compose(CUpdateOracle.OP_NAME, d => new CUpdateOracle(d))
+ case CSetOracleData.OP_CODE:
+ return compose(CSetOracleData.OP_NAME, d => new CSetOracleData(d))
+ case CAutoAuthPrep.OP_CODE:
+ return compose(CAutoAuthPrep.OP_NAME, () => new CAutoAuthPrep())
default:
return compose(CDeFiOpUnmapped.OP_NAME, d => new CDeFiOpUnmapped(d))
}
diff --git a/packages/jellyfish-transaction/src/script/defi/dftx_misc.ts b/packages/jellyfish-transaction/src/script/defi/dftx_misc.ts
new file mode 100644
index 0000000000..e713b9634a
--- /dev/null
+++ b/packages/jellyfish-transaction/src/script/defi/dftx_misc.ts
@@ -0,0 +1,21 @@
+import { BufferComposer, ComposableBuffer } from '../../buffer/buffer_composer'
+
+// Disabling no-return-assign makes the code cleaner with the setter and getter */
+/* eslint-disable no-return-assign */
+
+/**
+ * Composable UtxosToAccount, C stands for Composable.
+ * Immutable by design, bi-directional fromBuffer, toBuffer deep composer.
+ */
+export class CAutoAuthPrep extends ComposableBuffer<{}> {
+ static OP_CODE = 0x41 // 'A'
+ static OP_NAME = 'OP_DEFI_TX_AUTO_AUTH_PREP'
+
+ constructor () {
+ super({})
+ }
+
+ composers (): BufferComposer[] {
+ return []
+ }
+}
diff --git a/packages/jellyfish-transaction/src/script/defi/dftx_oracles.ts b/packages/jellyfish-transaction/src/script/defi/dftx_oracles.ts
new file mode 100644
index 0000000000..286de2454d
--- /dev/null
+++ b/packages/jellyfish-transaction/src/script/defi/dftx_oracles.ts
@@ -0,0 +1,110 @@
+import { BufferComposer, ComposableBuffer } from '../../buffer/buffer_composer'
+import { CurrencyPair, CCurrencyPair, CTokenPrice, TokenPrice } from './dftx_price'
+import { Script } from '../../tx'
+import { CScript } from '../../tx_composer'
+import BigNumber from 'bignumber.js'
+
+// Disabling no-return-assign makes the code cleaner with the setter and getter */
+/* eslint-disable no-return-assign */
+
+/**
+ * AppointOracle DeFi Transaction
+ */
+export interface AppointOracle {
+ script: Script // ---------------------| n = VarUInt{1-9 bytes}, + n bytes
+ weightage: number // ------------------| 1 byte unsigned int
+ priceFeeds: CurrencyPair[] // ---------| c = VarUInt{1-9 bytes}, + c x CurrencyPair
+}
+
+/**
+ * Composable AppointOracle, C stands for Composable.
+ * Immutable by design, bi-directional fromBuffer, toBuffer deep composer.
+ */
+export class CAppointOracle extends ComposableBuffer {
+ static OP_CODE = 0x6f
+ static OP_NAME = 'OP_DEFI_TX_APPOINT_ORACLE'
+
+ composers (ao: AppointOracle): BufferComposer[] {
+ return [
+ ComposableBuffer.single