Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wallet.sendMany RPC #269

Merged
merged 5 commits into from
May 25, 2021
Merged

Add wallet.sendMany RPC #269

merged 5 commits into from
May 25, 2021

Conversation

surangap
Copy link
Contributor

@surangap surangap commented May 21, 2021

What kind of PR is this?:

/kind feature

What this PR does / why we need it:

@codeclimate
Copy link

codeclimate bot commented May 21, 2021

Code Climate has analyzed commit 17ac805 and detected 0 issues on this pull request.

View more on Code Climate.

@netlify
Copy link

netlify bot commented May 21, 2021

Deploy Preview for jellyfish-defi ready!

Built with commit 17ac805

https://deploy-preview-269--jellyfish-defi.netlify.app

@fuxingloh fuxingloh changed the title Surangap/rpc sendmany added sendmany rpc May 21, 2021
await container.stop()
})

// util functions NOTE(sp) : may be move to a common util file if possible ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea we actually have it in @defichain/testing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@surangap you can keep it in this file as it is.

for api-core we try not to add too many test utils boilerplate (files) to keep the test scoped down for brevity. For other packages, e.g. the more complex use cases we have and uses a lot of testing utils. @canonbrother is maintaining the testing utilities now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We trying to contain the code debt so that it doesn't spaghetti around each other.

@github-actions
Copy link

github-actions bot commented May 21, 2021

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/jellyfish/dist/jellyfish.umd.js 19.16 KB (+0.38% 🔺) 384 ms (+0.38% 🔺) 178 ms (+6.6% 🔺) 561 ms

@codecov
Copy link

codecov bot commented May 21, 2021

Codecov Report

Merging #269 (a43cbe4) into main (cfbed46) will increase coverage by 0.24%.
The diff coverage is 100.00%.

❗ Current head a43cbe4 differs from pull request most recent head 17ac805. Consider uploading reports for the commit 17ac805 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #269      +/-   ##
==========================================
+ Coverage   96.37%   96.62%   +0.24%     
==========================================
  Files          82       87       +5     
  Lines        2153     2308     +155     
  Branches      275      297      +22     
==========================================
+ Hits         2075     2230     +155     
  Misses         78       78              
Impacted Files Coverage Δ
...ish-api-core/__tests__/container_adapter_client.ts 100.00% <100.00%> (ø)
...ages/jellyfish-api-core/src/category/blockchain.ts 100.00% <100.00%> (ø)
packages/jellyfish-api-core/src/category/mining.ts 100.00% <100.00%> (ø)
packages/jellyfish-api-core/src/category/wallet.ts 100.00% <100.00%> (ø)
packages/jellyfish-api-core/src/index.ts 100.00% <100.00%> (ø)
packages/jellyfish-api-jsonrpc/src/index.ts 97.43% <100.00%> (ø)
...ackages/jellyfish-transaction-builder/src/index.ts 100.00% <100.00%> (ø)
...transaction-builder/src/txn/txn_builder_account.ts 100.00% <100.00%> (ø)
...h-transaction-builder/src/txn/txn_builder_error.ts 100.00% <100.00%> (ø)
...ransaction-builder/src/txn/txn_builder_liq_pool.ts 100.00% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cfbed46...17ac805. Read the comment docs.

Comment on lines 679 to 684
it('should getBalance >= 100', async () => {
return await waitForExpect(async () => {
const balance: BigNumber = await client.wallet.getBalance()
expect(balance.isGreaterThan(new BigNumber('100'))).toBe(true)
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a part of test
suggestion here is to park this assertion on beforeAll()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. wil do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@surangap container has much more testing tools available now. You can take a look at those implementations and use them. If you need to add more please create PR for them.

https://github.com/DeFiCh/jellyfish/blob/63fd7700ef9959cc50bb2dadfc3cff202771aaab/packages/testcontainers/src/chains/reg_test_container/masternode.ts#L105-L114


expect(typeof transactionId).toBe('string')

// NOTE(sp): How to test the effect of confTarget
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps try getrawtransaction -> generate block -> getblock with minconf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confTarget is likely fees testing, meaning calculate the fee that confirms in 60 blocks. But you need to create 16MB of transactions to test that. Event mainnet don't hit that cap, so you don't need to test that behavior.

Copy link
Contributor

@canonbrother canonbrother left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finish the note to ensure the test completeness
btw like your code style

expect(utxos.length).toBe(1)
utxos.forEach(utxo => {
expect(utxo.address).toBe('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU')
expect(utxo.amount.isEqualTo(0.00001)).toBe(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toStrictEqual

* Returns matching utxos for given transaction id and address.
*
* @param {string} txId transaction id
* @param {string} address address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 address is enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't really need JSDoc for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jingyi2811 didn't quite understand your comment. input params for the function are txId and address

Copy link
Contributor

@jingyi2811 jingyi2811 May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay. You may remove the JSDoc.

@@ -213,6 +213,42 @@ export class Wallet {
async listAddressGroupings (): Promise<any[][][]> {
return await this.client.call('listaddressgroupings', [], 'bignumber')
}

/**
* Send given amounts to multiple given address and return a transaction id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like what you wrote in md file. Add a fullstop.

// In this case the we should only have one matching utxo
expect(utxos2.length).toBe(1)
utxos2.forEach(utxo => {
expect(utxo.address).toBe('mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy')
Copy link
Contributor

@jingyi2811 jingyi2811 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like what CanonBrother told me just now, change toBe to toStrictEqual

Copy link
Contributor

@fuxingloh fuxingloh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't review everything but added some comments


expect(typeof transactionId).toBe('string')

// NOTE(sp): How to test the effect of confTarget
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


it('should sendMany with confTarget', async () => {
const amounts: Record<string, number> = { mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU: 0.00001, mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy: 0.00002 }
return await waitForExpect(async () => {
Copy link
Contributor

@fuxingloh fuxingloh May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to use waitForExpect at all for sendMany tests, our setup should be deterministic now 🤞. Previously we had mempool conflict issues and a bunch of other flaky reasons. All those are fixed now. By using waitForExpect we can't detect race conditions error which is bad.

return matchingUTXOs
}

//= ==============================================================================================
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Comment on lines 679 to 684
it('should getBalance >= 100', async () => {
return await waitForExpect(async () => {
const balance: BigNumber = await client.wallet.getBalance()
expect(balance.isGreaterThan(new BigNumber('100'))).toBe(true)
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@surangap container has much more testing tools available now. You can take a look at those implementations and use them. If you need to add more please create PR for them.

https://github.com/DeFiCh/jellyfish/blob/63fd7700ef9959cc50bb2dadfc3cff202771aaab/packages/testcontainers/src/chains/reg_test_container/masternode.ts#L105-L114


expect(typeof transactionId).toBe('string')

// NOTE(sp): How to test the effect of confTarget
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confTarget is likely fees testing, meaning calculate the fee that confirms in 60 blocks. But you need to create 16MB of transactions to test that. Event mainnet don't hit that cap, so you don't need to test that behavior.

* Returns matching utxos for given transaction id and address.
*
* @param {string} txId transaction id
* @param {string} address address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't really need JSDoc for testing.

await container.stop()
})

// util functions NOTE(sp) : may be move to a common util file if possible ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@surangap you can keep it in this file as it is.

for api-core we try not to add too many test utils boilerplate (files) to keep the test scoped down for brevity. For other packages, e.g. the more complex use cases we have and uses a lot of testing utils. @canonbrother is maintaining the testing utilities now.

await container.stop()
})

// util functions NOTE(sp) : may be move to a common util file if possible ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We trying to contain the code debt so that it doesn't spaghetti around each other.

@fuxingloh fuxingloh marked this pull request as draft May 21, 2021 13:48
@surangap surangap marked this pull request as ready for review May 24, 2021 09:25
@surangap surangap requested a review from thedoublejay as a code owner May 24, 2021 09:25
Copy link
Contributor

@fuxingloh fuxingloh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 minor change

website/docs/jellyfish/api/wallet.md Show resolved Hide resolved
@fuxingloh fuxingloh changed the title added sendmany rpc Add wallet.sendMany RPC May 24, 2021
@fuxingloh fuxingloh marked this pull request as draft May 24, 2021 16:01
@surangap surangap marked this pull request as ready for review May 25, 2021 03:36
@fuxingloh fuxingloh enabled auto-merge (squash) May 25, 2021 03:36
@fuxingloh fuxingloh merged commit f38efc3 into main May 25, 2021
@fuxingloh fuxingloh deleted the surangap/rpc-sendmany branch May 25, 2021 03:46
canonbrother pushed a commit that referenced this pull request Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants