Skip to content

Commit

Permalink
Merge pull request #373 from nervosnetwork/rc/v0.23.1
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.23.1
  • Loading branch information
Keith-CY authored Oct 22, 2019
2 parents 4f06586 + 5641f5f commit 38424f4
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 18 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.23.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.23.0...v0.23.1) (2019-10-22)


### Features

* **utils** add methods for calculating transaction fee ([1dd82a4](https://github.com/nervosnetwork/ckb-sdk-js/commit/1dd82a4afba22f547406953444aa59df7e3a86bd))
1. add utils.serializeTransaction method to serialize a full transaction;
2. add utils.calculateTrasnactionSize to get the size of a full transaction





# [0.23.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.22.1...v0.23.0) (2019-10-19)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.23.0"
"version": "0.23.1"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.23.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.23.0...v0.23.1) (2019-10-22)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core





# [0.23.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.22.1...v0.23.0) (2019-10-19)


Expand Down
10 changes: 5 additions & 5 deletions packages/ckb-sdk-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-core",
"version": "0.23.0",
"version": "0.23.1",
"description": "JavaScript SDK for Nervos Network CKB Project",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -30,9 +30,9 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-rpc": "0.23.0",
"@nervosnetwork/ckb-sdk-utils": "0.23.0",
"@nervosnetwork/ckb-types": "0.23.0"
"@nervosnetwork/ckb-sdk-rpc": "0.23.1",
"@nervosnetwork/ckb-sdk-utils": "0.23.1",
"@nervosnetwork/ckb-types": "0.23.1"
},
"gitHead": "a8a15a57061e4edb378f50796257550c3522239b"
"gitHead": "10b8c08692e1b2fb2cf7e7aeb072a58e2f039dba"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-rpc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.23.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.23.0...v0.23.1) (2019-10-22)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc





# [0.23.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.22.1...v0.23.0) (2019-10-19)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc
Expand Down
8 changes: 4 additions & 4 deletions packages/ckb-sdk-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-rpc",
"version": "0.23.0",
"version": "0.23.1",
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
Expand Down Expand Up @@ -32,12 +32,12 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.23.0",
"@nervosnetwork/ckb-sdk-utils": "0.23.1",
"axios": "0.19.0"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.23.0",
"@nervosnetwork/ckb-types": "0.23.1",
"dotenv": "8.1.0"
},
"gitHead": "75ca98410be660b343f79a8f56380b218ac0ed1a"
"gitHead": "10b8c08692e1b2fb2cf7e7aeb072a58e2f039dba"
}
14 changes: 14 additions & 0 deletions packages/ckb-sdk-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.23.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.23.0...v0.23.1) (2019-10-22)


### Features

* **utils** add methods for calculating transaction fee ([1dd82a4](https://github.com/nervosnetwork/ckb-sdk-js/commit/1dd82a4afba22f547406953444aa59df7e3a86bd))
1. add utils.serializeTransaction method to serialize a full transaction;
2. add utils.calculateTrasnactionSize to get the size of a full transaction






# [0.23.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.22.1...v0.23.0) (2019-10-19)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@
"expected": "0x140000000c000000100000000000000000000000"
}
},
"serializeWitnesses": {
"empty witnesses": {
"witnesses": [],
"expected": "0x04000000"
},
"witnesses has multiple items": {
"witnesses": ["0x10", "0x01"],
"expected": "0x160000000c0000001100000001000000100100000001"
},
"witnesses has one item": {
"witnesses": ["0x3954acece65096bfa81258983ddb83915fc56bd8"],
"expected": "0x2000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8"
}
},
"serializeRawTransaction": {
"basic raw transaction": {
"rawTransaction": {
Expand Down Expand Up @@ -239,5 +253,67 @@
},
"expected": "0xb90100001c000000200000006e00000072000000a2000000a50100000000000002000000c12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b00000000010fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f6002000000000000000001000000000000000000000031f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc6501000000030100000c000000a20000009600000010000000180000006100000000e87648170000004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f600000000006100000010000000180000006100000000506a41e15900004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed020610061140000000c000000100000000000000000000000"
}
},
"serializeTransaction": {
"basic transaction": {
"transaction": {
"version": "0x0",
"cellDeps": [
{
"outPoint": {
"txHash": "0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"index": "0x0"
},
"depType": "depGroup"
},
{
"outPoint": {
"txHash": "0x0fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f60",
"index": "0x2"
},
"depType": "code"
}
],
"headerDeps": [],
"inputs": [
{
"previousOutput": {
"txHash": "0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"index": "0x1"
},
"since": "0x0"
}
],
"outputs": [
{
"capacity": "0x174876e800",
"lock": {
"codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"args": "0x59a27ef3ba84f061517d13f42cf44ed020610061",
"hashType": "type"
},
"type": {
"codeHash": "0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6",
"args": "0x",
"hashType": "data"
}
},
{
"capacity": "0x59e1416a5000",
"lock": {
"codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"args": "0x59a27ef3ba84f061517d13f42cf44ed020610061",
"hashType": "type"
},
"type": null
}
],
"outputsData": ["0x", "0x"],
"witnesses": [
"0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900"
]
},
"expected": "0x120200000c000000c5010000b90100001c000000200000006e00000072000000a2000000a50100000000000002000000c12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b00000000010fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f6002000000000000000001000000000000000000000031f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc6501000000030100000c000000a20000009600000010000000180000006100000000e87648170000004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f600000000006100000010000000180000006100000000506a41e15900004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed020610061140000000c0000001000000000000000000000004d000000080000004100000082df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const {
serializeOutput,
serializeOutputs,
serializeOutputsData,
serializeWitnesses,
serializeRawTransaction,
serializeTransaction,
} = require('../../../lib/serialization/transaction')
const fixtures = require('./fixtures.json')

Expand Down Expand Up @@ -173,6 +175,20 @@ describe('Test Transaction Serialization', () => {
})
})

describe('Serialize Witnesses', () => {
const fixtureTable = Object.entries(fixtures.serializeWitnesses).map(
([title, { witnesses, expected, exception }]) => [title, witnesses, expected, exception]
)
test.each(fixtureTable)('%s', (_title, witnesses, expected, exception) => {
if (undefined !== expected) {
expect(serializeWitnesses(witnesses)).toBe(expected)
}
if (undefined !== exception) {
expect(() => serializeWitnesses(witnesses)).toThrowError(exception)
}
})
})

describe('Serialize RawTransaction', () => {
const fixtureTable = Object.entries(fixtures.serializeRawTransaction).map(
([title, { rawTransaction, expected, exception }]) => [title, rawTransaction, expected, exception]
Expand All @@ -186,4 +202,18 @@ describe('Test Transaction Serialization', () => {
}
})
})

describe('Serialize Transaction', () => {
const fixtureTable = Object.entries(fixtures.serializeTransaction).map(
([title, { transaction, expected, exception }]) => [title, transaction, expected, exception]
)
test.each(fixtureTable)('%j', (_title, transaction, expected, exception) => {
if (undefined !== expected) {
expect(serializeTransaction(transaction)).toBe(expected)
}
if (undefined !== exception) {
expect(() => serializeTransaction(transaction)).toThrow(new Error(exception))
}
})
})
})
29 changes: 29 additions & 0 deletions packages/ckb-sdk-utils/__tests__/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const exceptions = require('../../lib/exceptions')
const bech32Fixtures = require('./bech32.fixtures.json')
const rawTransactionToHashFixtures = require('./rawTransactionToHash.fixtures.json')
const transformerFixtures = require('./transformer.fixtures.json')
const transactionFeeFixtures = require('./transactionFee.fixtures.json')
const transactionSizeFixture = require('./transactionSize.fixture.json')
const { ArgumentRequired } = require('../../lib/exceptions')

const {
Expand All @@ -25,6 +27,8 @@ const {
toHexInLittleEndian,
AddressType,
fullPayloadToAddress,
calculateTransactionFee,
calculateSerializedTxSizeInBlock,
} = ckbUtils

const { HexStringShouldStartWith0x, InvalidHexString } = exceptions
Expand Down Expand Up @@ -366,3 +370,28 @@ describe('address', () => {
expect(bytesToHex(parsedBytes)).toBe(`0x${fixture.hrp}${fixture.blake160Pubkey}`)
})
})

describe('transaction fee', () => {
const fixtureTable = Object.entries(transactionFeeFixtures).map(
([title, { transactionSize, feeRate, expected, exception }]) => [
title,
BigInt(transactionSize),
BigInt(feeRate),
BigInt(expected),
exception,
]
)
test.each(fixtureTable)('%s', (_title, transactionSize, feeRate, expected, exception) => {
if (undefined !== expected) {
expect(calculateTransactionFee(transactionSize, feeRate)).toBe(expected)
}
if (undefined !== exception) {
expect(() => calculateTransactionFee(transactionSize, feeRate)).toThrowError(exception)
}
})
})

describe('transaction size', () => {
const { transaction, expected } = transactionSizeFixture
expect(calculateSerializedTxSizeInBlock(transaction)).toBe(expected)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cell the fee": {
"transactionSize": 1035,
"feeRate": 900,
"expected": 932
},
"uncell the fee": {
"transactionSize": 900,
"feeRate": 900,
"expected": 810
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"transaction": {
"version": "0x0",
"cellDeps": [
{
"outPoint": {
"txHash": "0xc12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b",
"index": "0x0"
},
"depType": "depGroup"
},
{
"outPoint": {
"txHash": "0x0fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f60",
"index": "0x2"
},
"depType": "code"
}
],
"headerDeps": [],
"inputs": [
{
"previousOutput": {
"txHash": "0x31f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc65",
"index": "0x1"
},
"since": "0x0"
}
],
"outputs": [
{
"capacity": "0x174876e800",
"lock": {
"codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"args": "0x59a27ef3ba84f061517d13f42cf44ed020610061",
"hashType": "type"
},
"type": {
"codeHash": "0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6",
"args": "0x",
"hashType": "data"
}
},
{
"capacity": "0x59e1416a5000",
"lock": {
"codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88",
"args": "0x59a27ef3ba84f061517d13f42cf44ed020610061",
"hashType": "type"
},
"type": null
}
],
"outputsData": ["0x", "0x"],
"witnesses": [
"0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900"
]
},
"expected": 534
}
Loading

0 comments on commit 38424f4

Please sign in to comment.