Skip to content

Commit

Permalink
fix: fix typo in listeners
Browse files Browse the repository at this point in the history
fix: fix getTransactionProof input formatter
  • Loading branch information
Keith-CY committed Sep 15, 2018
1 parent 3c1b1d7 commit cfbc2f2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ The `nervos.js` library is a collection of packages which contains specific func
- [update]: **Lower Address**, lower `to` address in transaction when sendTransaction;
- [update]: **Format Address**, remove `0x` in `to` address;
- [feature]: **PrivateKey Validator**, add `nervos.utils.isPrivateKey(privateKey)` to check private key format;
- [fix]: **Fix Typo**, fix typo in log of transactionReceipt listener;
- [fix]: **Fix getTransactionProof**, fix rpc input formatter;
13 changes: 12 additions & 1 deletion packages/nervos-chain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,18 @@ nervos.appchain.sendSignedTransaction('signedTransaction')
* @return {Promise<object>} Promise returns transaction receipt object
*/
nervos.appchain.getTransactionReceipt('0x6fc32e7bdcb8040c4f587c3e9e6cfcee4025ea58')
nervos.appchain.getTransactionReceipt('0xe418a9cf4f4257aaed8c4c1259d30fb41ea650f4b4ef95ebb28cb3b29ccb1d91')
```
```javascript
/**
* @method getTransactionProof
* @desc request transaction proof
* @param {string} - transaction hash
* @return {Promise<string>} Promise returns transaction proof
*/
nervos.appchain.getTransactionProof('0xe418a9cf4f4257aaed8c4c1259d30fb41ea650f4b4ef95ebb28cb3b29ccb1d91')
```
### getTransaction
Expand Down
2 changes: 1 addition & 1 deletion packages/nervos-chain/lib/appchain/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const listener = (web3) => {
listener = setInterval(() => {
if (!remains) {
stopWatching();
reject('No Result Receved');
reject('No Result Received');
}
web3.appchain[action](params).then((res) => {
remains--;
Expand Down
1 change: 0 additions & 1 deletion packages/nervos-chain/lib/appchain/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ exports.getTransactionProof = {
name: 'getTransactionProof',
call: 'getTransactionProof',
params: 1,
inputFormatter: [formatters.inputAddressFormatter]
};
exports.sendSignedTransaction = {
name: 'sendSignedTransaction',
Expand Down
2 changes: 1 addition & 1 deletion packages/nervos-chain/lib/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/nervos-chain/src/appchain/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const listener = (web3: EnhancedWeb3) => {
listener = setInterval(() => {
if (!remains) {
stopWatching()
reject('No Result Receved')
reject('No Result Received')
}
web3.appchain[action](params).then((res: any) => {
remains--
Expand Down
3 changes: 1 addition & 2 deletions packages/nervos-chain/src/appchain/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ export const getTransactionCount = {
export const getTransactionProof = {
name: 'getTransactionProof',
call: 'getTransactionProof',
params: 1,
inputFormatter: [formatters.inputAddressFormatter]
params: 1
}

export const sendSignedTransaction = {
Expand Down
24 changes: 14 additions & 10 deletions packages/nervos-chain/test/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const {
tx
} = require('./config')

const inquireReceipt = txHash =>
const inquireTx = (action = 'getTransactionReceipt') => txHash =>
new Promise((resolve, reject) => {
let remains = 10
let interval = setInterval(() => {
if (!remains) {
clearInterval(interval)
reject(new Error('No Receipt Received'))
reject(new Error('No Result Received'))
}
remains--
nervos.appchain.getTransactionReceipt(txHash).then(receipt => {
if (receipt && receipt.transactionHash) {
nervos.appchain[action](txHash).then(res => {
if (res) {
clearInterval(interval)
resolve(receipt)
resolve(res)
}
})
}, 1000)
Expand All @@ -32,8 +32,8 @@ test.skip('sendSignedTransaction', () => {
//
})

test('sendTransaction, getTransactionReceipt, and getTransaction', async () => {
expect.assertions(5)
test('sendTransaction, getTransactionReceipt, getTransactionProof, and getTransaction', async () => {
expect.assertions(6)
jest.setTimeout(30000)
const currentHeight = await nervos.appchain.getBlockNumber()
const result = await nervos.appchain.sendTransaction({
Expand All @@ -47,13 +47,17 @@ test('sendTransaction, getTransactionReceipt, and getTransaction', async () => {
return new Error('No TxHash Received')
}

const receipt = await inquireReceipt(result.hash)
const receipt = await inquireTx('getTransactionReceipt')(result.hash)

expect(receipt.transactionHash).toBe(result.hash)
expect(receipt.errorMessages).not.toBeNull()
//TODO: getTransactionProof

const proof = await inquireTx('getTransactionProof')(result.hash)
expect(proof).not.toBeNull()

const transactionResult = await nervos.appchain.getTransaction(result.hash)
expect(transactionResult.hash).toBe(result.hash)

return
})

Expand All @@ -79,7 +83,7 @@ test('transfer', async () => {
return new Error('No TxHash Received')
}

const receipt = await inquireReceipt(result.hash)
const receipt = await inquireTx('getTransactionReceipt')(result.hash)

expect(receipt.transactionHash).toBe(result.hash)
expect(receipt.errorMessages).not.toBeNull()
Expand Down

0 comments on commit cfbc2f2

Please sign in to comment.