Skip to content

Commit

Permalink
refactor module exports for api-core & crypto (#168)
Browse files Browse the repository at this point in the history
* jellyfish-crypto to exports Elliptic, WIF & Bech32 instead of functions

* added [optional] js docs symbols

* cleanup js docs and website docs, refactor exports to have top level named module

* fixed tests in jellyfish-api-core

* updated testcontainers dependencies
  • Loading branch information
fuxingloh authored Apr 28, 2021
1 parent eba378d commit 4569f64
Show file tree
Hide file tree
Showing 36 changed files with 362 additions and 242 deletions.
3 changes: 2 additions & 1 deletion .idea/dictionaries/fuxing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ Package | Description
## Developing & Contributing
Thanks for contributing, appreciate all the help we can get. Feel free to make a pull-request, we will guide you along
the way to make it mergeable. Here are some of our documented [contributing guidelines](CONTRIBUTING.md).
the way to make it merge-able. Here are some of our documented [contributing guidelines](CONTRIBUTING.md).
We use `npm 7` for this project, it's required to set
You need `node v14`, and `npm v7` for this project, it's required to set
up [npm workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces).
```shell
Expand All @@ -112,14 +112,15 @@ npm install
### Testing
`jest.config.js` is set up at the root project level as well as at each sub module. You can run jest at root to test all
modules or individually at each sub module. By default, only regtest chain are used for normal testing. If you use
IntelliJ IDEA, you can right click any file to test it individually and have it reported to the IDE.
`jest.config.js` is set up at the root project level as well as at each submodule. You can run jest at root to test all
modules or individually at each submodule. By default, only regtest chain are used for normal testing. If you use
IntelliJ IDEA, you can right-click any file to test it individually and have it reported to the IDE.
Docker is required to run the tests as [`@defichain/testcontainers`](./packages/testcontainers) will automatically spin
up `regtest` instances for testing. The number of containers it will spin up concurrently is dependent on your
jest `--maxConcurrency` count. Test are known to be flaky due to the usage of multiple Docker containers for test
concurrency.
concurrency. Although testcontainers cleans up after itself, there are cases where the tests fail exceptionally you
might need to occasionally: `docker system prune --volumes`.
Coverage is collected at each pull request to main with `codecov`; more testing 🚀 less 🐛 = 😎
Expand Down
76 changes: 50 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/jellyfish-api-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ handling with rich structure.
regular numeric operations, and it will throw an error when this would result in losing information.
* **'bignumber'** parse all numeric values as 'BigNumber' using bignumber.js library.
* **'number'** parse all numeric values as 'Number' and precision will be loss if it exceeds IEEE-754 standard.
* **'PrecisionPath'** provides path based precision mapping, specifying 'bignumber' will automatically map all Number in
that path as 'bignumber'. Otherwise, it will default to number, This applies deeply.

## Testing

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RegTestContainer, MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../container_adapter_client'
import waitForExpect from 'wait-for-expect'
import { BigNumber, Block, BlockHeader, MempoolTx, Transaction, WalletFlag } from '../../src'
import { BigNumber, blockchain, wallet } from '../../src'

describe('non masternode', () => {
const container = new RegTestContainer()
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('masternode', () => {

it('should getBlock with verbosity 1 and return block with tx as hex', async () => {
const blockHash = await waitForBlockHash(1)
const block: Block<string> = await client.blockchain.getBlock(blockHash, 1)
const block: blockchain.Block<string> = await client.blockchain.getBlock(blockHash, 1)

expect(block.hash.length).toBe(64)

Expand Down Expand Up @@ -139,7 +139,7 @@ describe('masternode', () => {

it('should getBlock with verbosity 2 and return block with tx as RawText', async () => {
const blockHash = await waitForBlockHash(1)
const block: Block<Transaction> = await client.blockchain.getBlock(blockHash, 2)
const block: blockchain.Block<blockchain.Transaction> = await client.blockchain.getBlock(blockHash, 2)

expect(block.tx.length).toBeGreaterThanOrEqual(1)
expect(block.tx[0].vin[0].coinbase).toStrictEqual('5100')
Expand All @@ -159,7 +159,7 @@ describe('masternode', () => {
describe('getBlockHeader', () => {
it('should getBlockHeader with verbosity true and return block with tx as hex', async () => {
const blockHash = await waitForBlockHash(1)
const blockHeader: BlockHeader = await client.blockchain.getBlockHeader(blockHash, true)
const blockHeader: blockchain.BlockHeader = await client.blockchain.getBlockHeader(blockHash, true)

expect(blockHeader.hash.length).toBe(64)

Expand Down Expand Up @@ -236,7 +236,7 @@ describe('masternode', () => {
let transactionId = ''

beforeAll(async () => {
await client.wallet.setWalletFlag(WalletFlag.AVOID_REUSE)
await client.wallet.setWalletFlag(wallet.WalletFlag.AVOID_REUSE)
transactionId = await client.wallet.sendToAddress('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU', 0.00001)
})

Expand All @@ -248,7 +248,7 @@ describe('masternode', () => {
})

it('should getRawMempool and return json object', async () => {
const rawMempool: MempoolTx = await client.blockchain.getRawMempool(true)
const rawMempool: blockchain.MempoolTx = await client.blockchain.getRawMempool(true)

const data = rawMempool[transactionId]
expect(data.fees.base instanceof BigNumber).toBe(true)
Expand Down
22 changes: 11 additions & 11 deletions packages/jellyfish-api-core/__tests__/category/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContainerAdapterClient } from '../container_adapter_client'
import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers'
import { BigNumber, ValidateAddressResult, AddressType, AddressInfo } from '../../src'
import { BigNumber, wallet } from '../../src'
import waitForExpect from 'wait-for-expect'
import { UTXO, ListUnspentOptions, WalletFlag, SendToAddressOptions, Mode } from '../../src/category/wallet'

Expand Down Expand Up @@ -44,13 +44,13 @@ describe('non masternode', () => {

it('should getNewAddress with address type specified', async () => {
return await waitForExpect(async () => {
const legacyAddress = await client.wallet.getNewAddress('', AddressType.LEGACY)
const legacyAddress = await client.wallet.getNewAddress('', wallet.AddressType.LEGACY)
const legacyAddressValidateResult = await client.wallet.validateAddress(legacyAddress)

const p2shSegwitAddress = await client.wallet.getNewAddress('', AddressType.P2SH_SEGWIT)
const p2shSegwitAddress = await client.wallet.getNewAddress('', wallet.AddressType.P2SH_SEGWIT)
const p2shSegwitAddressValidateResult = await client.wallet.validateAddress(p2shSegwitAddress)

const bech32Address = await client.wallet.getNewAddress('bob', AddressType.BECH32)
const bech32Address = await client.wallet.getNewAddress('bob', wallet.AddressType.BECH32)
const bech32AddressValidateResult = await client.wallet.validateAddress(bech32Address)

expect(typeof legacyAddress).toBe('string')
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('non masternode', () => {
it('should getAddressInfo', async () => {
return await waitForExpect(async () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const addressInfo: AddressInfo = await client.wallet.getAddressInfo(aliceAddress)
const addressInfo: wallet.AddressInfo = await client.wallet.getAddressInfo(aliceAddress)

expect(addressInfo.address).toBe(aliceAddress)
expect(typeof addressInfo.scriptPubKey).toBe('string')
Expand All @@ -108,7 +108,7 @@ describe('non masternode', () => {
it('should validateAddress', async () => {
return await waitForExpect(async () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const result: ValidateAddressResult = await client.wallet.validateAddress(aliceAddress)
const result: wallet.ValidateAddressResult = await client.wallet.validateAddress(aliceAddress)

expect(result.isvalid).toBe(true)
expect(result.address).toBe(aliceAddress)
Expand Down Expand Up @@ -377,13 +377,13 @@ describe('masternode', () => {

it('should getNewAddress with address type specified', async () => {
return await waitForExpect(async () => {
const legacyAddress = await client.wallet.getNewAddress('', AddressType.LEGACY)
const legacyAddress = await client.wallet.getNewAddress('', wallet.AddressType.LEGACY)
const legacyAddressValidateResult = await client.wallet.validateAddress(legacyAddress)

const p2shSegwitAddress = await client.wallet.getNewAddress('', AddressType.P2SH_SEGWIT)
const p2shSegwitAddress = await client.wallet.getNewAddress('', wallet.AddressType.P2SH_SEGWIT)
const p2shSegwitAddressValidateResult = await client.wallet.validateAddress(p2shSegwitAddress)

const bech32Address = await client.wallet.getNewAddress('bob', AddressType.BECH32)
const bech32Address = await client.wallet.getNewAddress('bob', wallet.AddressType.BECH32)
const bech32AddressValidateResult = await client.wallet.validateAddress(bech32Address)

expect(typeof legacyAddress).toBe('string')
Expand Down Expand Up @@ -414,7 +414,7 @@ describe('masternode', () => {
it('should getAddressInfo', async () => {
return await waitForExpect(async () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const addressInfo: AddressInfo = await client.wallet.getAddressInfo(aliceAddress)
const addressInfo: wallet.AddressInfo = await client.wallet.getAddressInfo(aliceAddress)

expect(addressInfo.address).toBe(aliceAddress)
expect(typeof addressInfo.scriptPubKey).toBe('string')
Expand All @@ -441,7 +441,7 @@ describe('masternode', () => {
it('should validateAddress', async () => {
return await waitForExpect(async () => {
const aliceAddress = await client.wallet.getNewAddress('alice')
const result: ValidateAddressResult = await client.wallet.validateAddress(aliceAddress)
const result: wallet.ValidateAddressResult = await client.wallet.validateAddress(aliceAddress)

expect(result.isvalid).toBe(true)
expect(result.address).toBe(aliceAddress)
Expand Down
Loading

0 comments on commit 4569f64

Please sign in to comment.