Compare commits

..

139 Commits

Author SHA1 Message Date
Nathan Nichols
8e9c922e41 adjust 2021-10-05 11:15:53 -07:00
Nathan Nichols
e71123ad9d more debug 2021-10-05 10:57:52 -07:00
Nathan Nichols
248445acd9 DEBUG STUFF 2021-10-05 10:52:51 -07:00
Nathan Nichols
403b0c402a docs: Add @beta to npm install instructions 2021-10-04 14:11:26 -04:00
Nathan Nichols
0644e0467b docs: updates README adding @beta to npm install 2021-10-04 14:11:26 -04:00
Nathan Nichols
578f35dd35 fix: convert uint8Array to Buffer (#1679) 2021-10-04 14:11:26 -04:00
Mukul Jangid
a1dce6b1e0 test: Integration tests for Account Transactions (#1673)
* test: Integration tests for Account Transactions
2021-10-04 14:11:26 -04:00
Nathan Nichols
8df224232c fix: remove undefined from generateFaucetWallet return type (#1676)
* fix: remove undefined from generateFaucetWallet return type
2021-10-04 14:11:26 -04:00
Nathan Nichols
c3e68cc83f fix: set ledger_index to validated (#1675)
* fix: adds ledger_index: validated
2021-10-04 14:11:26 -04:00
Nathan Nichols
02fd0ce323 refactor: clean up getFaucetWallet starting balance (#1677) 2021-10-04 14:11:26 -04:00
Nathan Nichols
5b9e3dbdc4 refactor: separate out webpacking for tests (#1678) 2021-10-04 14:11:26 -04:00
Mayukha Vadari
e65d686cc7 build: update beta version to beta.2 (#1674) 2021-10-04 14:11:26 -04:00
Mukul Jangid
b77e2590b3 test: add integration tests for Server Info requests (#1650)
* add Integration tests for Server Info requests
2021-10-04 14:11:26 -04:00
Nathan Nichols
9e3654d7d6 fix: fix error handling in generateFaucetWallet (#1671)
* fix: handle error correctly in generateFaucetWallet
* test: Adds generateFaucetWallet integration + browser tests
2021-10-04 14:11:26 -04:00
Nathan Nichols
edcdd3a0fc feat: adds isValidAddress (#1672)
* feat: adds isValidAddress
2021-10-04 14:11:26 -04:00
Mayukha Vadari
f5dee87ca7 fix: make generateFaucetWallet functional (#1669) 2021-10-04 14:11:26 -04:00
Mayukha Vadari
b522e703b4 feat: add client.getLedgerIndex (#1668)
* write getLedgerIndex

* add to client

* rename file

* add tests

* remove unused import

* fix browser tests

* respond to comments, more cleanup
2021-10-04 14:11:26 -04:00
Nathan Nichols
0be819cf37 feat: Add warning for partial payment (#1641) 2021-10-04 14:11:26 -04:00
Jackson Mills
afe06451ac Add trustSet integration test and browser test (#1667) 2021-10-04 14:11:26 -04:00
Mayukha Vadari
da92bb7f1a fix: resolve browser issue with Error.captureStackTrace (#1663)
* fix webpacking error issue

* fix eslint comment
2021-10-04 14:11:26 -04:00
Nathan Nichols
0996dc13b7 fix: adds mode to webpack to stop warning (#1666) 2021-10-04 14:11:26 -04:00
Nathan Nichols
b3a72588ea Autofills AccountDelete Fee w/ reserve_inc_xrp (#1639)
* fix: fetch Owner Reserves from ledger
2021-10-04 14:11:26 -04:00
Mayukha Vadari
1747b31a02 chore: remove ripple-lib-transactionparser (#1661) 2021-10-04 14:11:26 -04:00
Mayukha Vadari
b7c4b16a8d feat: extra protection for AccountDelete transactions (#1626)
* add deletion blockers check to autofill

* add tests

* add fail_hard: true

* pass in account_objects response to error

* only fail_hard for AccountDelete

* reject promise instead of throwing error

* fix rebase issue
2021-10-04 14:11:26 -04:00
Mayukha Vadari
bfeb737ad7 fix: disallow two pending requests with the same id (#1628)
* only increment nextId if id used

* throw error if promise already pending with id

* add test

* modify existing tests

* fix bug + tests
2021-10-04 14:11:26 -04:00
Jackson Mills
cc0b5a4ac9 test: Add PayChannel Transaction Integration Tests (#1662)
* Add test for PaymentChannelCreate

* Add PaymentChannelFund test

* Add PaymentChannelClaim test
2021-10-04 14:11:26 -04:00
Jackson Mills
dcfc31a036 Add Payment Channel Tests (#1646)
* Add ChannelVerify integration and browser test
2021-10-04 14:11:26 -04:00
Jackson Mills
955e21717a Add Path and Orderbook integration tests (#1644)
Add bookOrder, depositAuthorized, and ripplePathFind, and pathFind integration and browser tests
2021-10-04 14:11:26 -04:00
Mayukha Vadari
5200682915 build: prepare repo for beta release (#1665)
* fix github links

* fix webpacking

* more cleanup

* add 2.x to SECURITY.md

* update beta version
2021-10-04 14:11:20 -04:00
Jackson Mills
297dee9b8f Add Ledger Method Integration Tests (#1640)
Add integration tests for ledger, ledgerEntry, ledgerData, ledgerClosed and ledgerCurrent, plus add them to the browser tests.
2021-10-04 14:10:14 -04:00
Mayukha Vadari
5d67f14ea3 test: integration tests for CheckCreate, CheckCancel, CheckCash (#1664)
* test checkCreate

* test CheckCancel

* test CheckCash

* add browser tests
2021-10-04 14:10:14 -04:00
Mayukha Vadari
564001515d test: add integration tests for Account requests (#1643) 2021-10-04 14:10:14 -04:00
Jackson Mills
b5b2909fed Add integration tests for Transaction methods (#1636)
Add tx, submit, and submit_multisign integration tests, along with browser tests.
2021-10-04 14:10:14 -04:00
Mayukha Vadari
2a93f85f41 test: integration tests for DepositPreauth (#1648) 2021-10-04 14:10:13 -04:00
Nathan Nichols
dd068c2710 build: adjust for updates to @xrplf/eslint-config (#1633) 2021-10-04 14:10:13 -04:00
Mukul Jangid
f2216446e5 test: write tests for sugar functions (#1631)
* test: write tests for sugar functions
2021-10-04 14:10:13 -04:00
Mayukha Vadari
98c9b9bc14 ci: run lint tests (#1603)
* turn on lint tests

* remove tsc

* fix errors in src/utils/hashes

* fix linter errors in src/utils

* fix lint issues in test/

* resolve lint issues in src/client

* resolve dependency cycle

* resolve other linting issues in src/models

* resolve rest of linting issues

* fix tests

* fix linting errors in test/integration

* fix rest of linting issues

* fix test name
2021-10-04 14:10:13 -04:00
Mayukha Vadari
57a6586898 fix: run browser tests on all integration tests (#1649)
* attempt to webpack all tests

* fix browser tests

* remove console.log
2021-10-04 14:10:13 -04:00
Nathan Nichols
c5f47cbffc rename browser library (#1637)
* rename browser library
2021-10-04 14:10:13 -04:00
Mayukha Vadari
6dba1b142c refactor: remove client.combine (#1632)
* remove combine

* remove tests

* fix tests
2021-10-04 14:10:13 -04:00
Nathan Nichols
d734d886c4 Resolves TODOs in ./src/client (#1617)
* fix: fixes TODO's in ./src/client
2021-10-04 14:10:13 -04:00
Mayukha Vadari
8e1ab6c32b test: add integration tests for OfferCreate, OfferCancel (#1634)
* test OfferCreate

* test OfferCancel
2021-10-04 14:10:13 -04:00
Mayukha Vadari
dac8c27b49 test: integration tests for Payment (#1635)
* test payment

* use new helper function elsewhere

* remove unneeded comment
2021-10-04 14:10:13 -04:00
Mayukha Vadari
6eec7b0b77 refactor: move everything out of the common folder (#1629)
* remove common/constants (all in models now)

* remove common/txFlags (all in models now)

* move ecdsa from src/common to src

* move errors from src/common to src, export at top level
2021-10-04 14:10:13 -04:00
Jackson Mills
94a8c65200 Remove old types (#1630)
* Remove transaction/types

* Delete common/types/commands

* Delete common/types
2021-10-04 14:10:13 -04:00
Jackson Mills
6fac420d9f Remove sign.ts and move functionality into Wallet (#1620)
* Move sign.ts functionality into Wallet
* Move the corresponding tests to wallet's test cases and simplify them for readability
* Delete sign.ts
2021-10-04 14:10:13 -04:00
Mayukha Vadari
05e1d4d3c5 test: SignerListSet transaction integration tests (#1621)
* add tests

* clean up helper functions

* fix account funding

* remove unneeded method

* use new wallets for each test

* automatically fund wallets

* fix TODO
2021-10-04 14:10:13 -04:00
Mayukha Vadari
e53df109b0 refactor: move address-codec methods from client to utils (#1627) 2021-10-04 14:10:13 -04:00
Mayukha Vadari
dbb134839a refactor: remove unused methods/types in src/sugar (#1625)
* remove sugar/utils

* remove sugar/pathfind-types

* clean up src/sugar/index
2021-10-04 14:10:13 -04:00
Mayukha Vadari
13c52859eb fix: renames verify... methods to validate... (#1624)
* rename verify -> validate

* fix imports

* run eslint --fix on test/
2021-10-04 14:10:13 -04:00
Mayukha Vadari
eb0445817e refactor: adds error response object (#1619)
* add error response object

* export error response properly

* type mockRippled

* fix linter

* fix ts

* fix comments
2021-10-04 14:10:13 -04:00
Mukul Jangid
10445cff01 Refactor: Lint test/client (#1602)
* lint test/client
2021-10-04 14:10:13 -04:00
Nathan Nichols
3cbdbac4f9 fix: remove the sugar/parse directory (#1622)
* fix: remove the sugar/parse directory

* feat: adds lsf flags
2021-10-04 14:10:13 -04:00
Mukul Jangid
fd78d1edcd refactor: Reimplement sugar functions and clean up (#1559)
* refactor: Reimplement sugar functions and clean up
2021-10-04 14:10:13 -04:00
Jackson Mills
603b7ae85c Add Wallet.fromSecret(...) as an alias for Wallet.fromSeed(...) (#1618)
* Add alias to fromSeed for fromSecret

* Switch syntax to direct usage
2021-10-04 14:10:12 -04:00
Mayukha Vadari
fcc8977623 test: adds integration tests for rippled utility methods (#1597)
* add utility tests

* type client better

* simplify ledgerAccept
2021-10-04 14:10:12 -04:00
Nathan Nichols
b9b32eb3d2 docs: generate documentation with typedoc (#1607)
* docs: generate documentation with typedoc
2021-10-04 14:10:12 -04:00
Jackson Mills
1037e0da88 Remove deprecated deriveAddress from Client (#1614)
* Removing deriveAddress and X from client

* Remove deriveAddress from derive.ts

* Remove linting exception for function lines
2021-10-04 14:10:12 -04:00
Jackson Mills
29c0b84ad5 Update integration test with multisign changes (#1616) 2021-10-04 14:10:12 -04:00
Jackson Mills
4f1e1d653c Change multisign to return an encoded transaction (#1615) 2021-10-04 14:10:12 -04:00
Mayukha Vadari
fe919315d4 Lints src/wallet and test/wallet (#1600)
* lint src/wallet/index

* lint generateFaucetWallet

* lint tests

* respond to comments

* change max-lines-per-function to 40

* remove * import

* fix TS issues
2021-10-04 14:10:12 -04:00
Mayukha Vadari
3f29e5781d Lint integration test files and browser test files (#1612)
* clean up utils

* more cleanup

* remove client.sign

* remove unneeded tests

* remove unneeded infra

* move helper functions to separate files

* fix linter issues

* more cleanup

* make helper functions more generally useful

* fix test account funding

* add import note to README

* lint browser tests

* run eslint --fix
2021-10-04 14:10:12 -04:00
Nathan Nichols
0dc1e08350 build: update typescript version (#1601) 2021-10-04 14:10:12 -04:00
Mukul Jangid
148cac6f3f refactor: add verify() function (#1552)
* refactor: add verify() function
2021-10-04 14:10:12 -04:00
Nathan Nichols
0d32071e0e build: bump ws version (#1606) 2021-10-04 14:10:12 -04:00
Mayukha Vadari
e7e0ece78b build: update version for beta (#1613) 2021-10-04 14:10:12 -04:00
Omar Khan
dc6baf7f39 add submit transaction methods (#1611)
Adds submit transaction methods: submitTransaction and submitSignedTransaction.
2021-10-04 14:10:12 -04:00
Nathan Nichols
851b352f32 feat: cleanup flag naming (#1609)
* feat: cleanup flag naming
2021-10-04 14:10:12 -04:00
Nathan Nichols
633032ddd8 Lint utils directory (#1563)
* Lint the utils directory

* Modify computeLedgerHash to take new Ledger format.
2021-10-04 14:10:12 -04:00
Nathan Nichols
33f83947f1 build: rename ripple-lib to xrpl.js (#1608)
* build: rename ripple-lib to xrpl.js
2021-10-04 14:10:12 -04:00
Mayukha Vadari
af7b187dc7 Removes all prepare methods (#1605)
* deprecate and alias prepareTransaction

* delete prepareTransaction and replace methods in check-cancel

* WIP update check-cash

* remove all prepares

* remove prepares from client

* fix ts issues

* remove tests

* fix tests

* additional cleanup

* fix integration tests

* remove console statement

* re-add helper function

* fix imports

* fix more issues with integration tests

Co-authored-by: Omar Khan <khancodegt@gmail.com>
2021-10-04 14:10:12 -04:00
Jackson Mills
1115f17a3e Refactoring existing hash utils and adding tests (#1557)
Write toHash utils and tests, then fix naming to match our standards of camelCase
2021-10-04 14:10:12 -04:00
Nathan Nichols
ac66c2174a build: remove linter rules already in base config (#1599) 2021-10-04 14:10:12 -04:00
Jackson Mills
eb56eb181a Signer fixes (#1604)
* Factor out reused wallet generation
* Remove extraneous types
* Clarify that multisign takes signed transactions

Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
2021-10-04 14:10:12 -04:00
Jackson Mills
c401f703c7 Signer (#1573)
Create Signer class to allow for offline signing, multisigning and signing authorizeChannel requests.
2021-10-04 14:10:12 -04:00
Omar Khan
04dd65af38 implement Autofill Transaction (#1574)
Implements autofill() and setTransactionFlagsToNumber() to allow a Client to autofill fields in a Transaction.
2021-10-04 14:10:12 -04:00
Mayukha Vadari
949cc031ee Lints top-level test files (#1594)
* lint broadcastClient

* lint client

* fix most of connection

* remove unused files

* lint mockRippled

* lint mockRippledTest

* lint runClientTests

* lint setupClient

* lint setupClientWeb

* lint shamap

* lint testUtils

* resolve tsc issues

* Fix tests

* lint rest of connection

* respond to comments
2021-10-04 14:10:12 -04:00
Nathan Nichols
c8a2a6690b feat: Add typescript types to subscribe (#1576)
feat: Add typescript types to subscribe (#1576)
2021-10-04 14:10:12 -04:00
Mayukha Vadari
a996fafe79 Lints src/common (#1595)
* lint errors (and remove unused error types)

* lint fee

* lint index

* lint ecdsa

* fix tests

* remove address tests from getFee

* fix more tests

* fix tests

* respond to comments
2021-10-04 14:10:11 -04:00
Nathan Nichols
e200de3073 Adds @xrplf prettier config (#1598)
* build: new prettier config
2021-10-04 14:10:11 -04:00
Mayukha Vadari
8c5bc22317 Lints src/client (#1577)
* lint backoff

* lint wsWrapper

* remove rangeset - not used

* split out connection.ts classes

* lint requestManager

* lint connectionManager

* lint most of connection

* fix most of client

* lint broadcastClient

* resolve more linter issues

* resolve magic numbers

* clean up more linting

* resolve rest of issues

* fix tests

* fix browser tests

* fix tests after rebase

* respond to comments

* fix dependency cycles
2021-10-04 14:10:11 -04:00
Mayukha Vadari
aa6cef520c Removes jsonschemas (#1593)
* remove jsonschemas stuff

* fix ts issues

* fix tests

* remove package

* remove scripts

* replace isValidAddress
2021-10-04 14:10:11 -04:00
Mayukha Vadari
2ca164311b Lints test/models (#1578) 2021-10-04 14:10:11 -04:00
Nathan Nichols
3f365d8591 update integration testing readme (#1589)
* update integration testing `README.md`
2021-10-04 14:10:11 -04:00
Omar Khan
e0f4d99d86 Refactor generateFaucetWallet to return a Wallet (#1564)
* add Wallet.generate() and 

* return Wallet in generateFaucetWallet

* refactor Wallet tests

* rename wallet-generation.ts to generateFaucetWallet.ts

* rename and move Wallet.ts to src/wallet/index.ts and update webpack config
2021-10-04 14:10:11 -04:00
Mayukha Vadari
62538a75b1 Switches from yarn to npm (#1591)
* remove yarn.lock

* reinstall with npm

* fix package.json

* update xrplf eslint

* fix all other instances of yarn
2021-10-04 14:10:11 -04:00
Mayukha Vadari
91cc9e0461 Lints test/utils (#1575)
* rename model tests

* rename util tests

* turn off `any` complaints in linter

* other linter changes

* fix xrp <-> drops methods

* lint generateAddress

* fix rest of tests
2021-10-04 14:10:11 -04:00
Mayukha Vadari
b53bc2bc97 Lints src/models (#1572)
* resolve src/models/methods

* PaymentTransaction => Payment, remove empty returns

* fix common, method signatures

* fix checkCash

* handle complexity complaints

* fix jsdocs

* handle magic numbers

* finish models/transactions

* fix models/utils

* fix models/ledger

* fix ts issues

* fix tests

* fix modifiedoffercreatetransaction

* remove comments, fix additional TODO
2021-10-04 14:10:11 -04:00
Nathan Nichols
75f0bb4617 refactor: migrate fixtures to use typescript (#1565)
* refactor: migrate fixtures to typescript
2021-10-04 14:10:11 -04:00
Mayukha Vadari
6268b9ea26 test: removes the use of TestSuite (#1566)* switch all methods to new format* clean up rippleClient* rename files to remove ripple from name* additional cleanup 2021-10-04 14:10:11 -04:00
Omar Khan
43802f9e22 add getXAddress to Wallet (#1558)
- add getXAddress to Wallet
- refactor wallet tests
2021-10-04 14:10:11 -04:00
Mayukha Vadari
b8be6c2f1b refactor: improves mock rippled structure (#1569)
* better error handling + tests

* fix tests

* change addResponse to take a string instead of a Request

* remove unneeded change

* respond to comments

* fix tests, re-lint

* improve error message
2021-10-04 14:10:11 -04:00
Mayukha Vadari
759e075e54 refactor: use chai instead of assert-diff (#1570)
* assert-diff -> chai

* fix tests

* remove package

* fix rebase
2021-10-04 14:10:11 -04:00
Nathan Nichols
8b95ee5fab build: Initial linting setup (#1560)
* sets up linting config and runs `yarn lint --fix` once, so that all changes will show up correctly in future PRs.

* Note that there are still a lot of linter errors.
2021-10-04 14:10:10 -04:00
Mayukha Vadari
12cfed5c17 refactor: clean up Client and associated files (#1556)
* remove _PRIVATE

* make requestAll public

* un-type connection.request

* fix lodash imports

* add comments

* Rename files to camelCase
2021-10-04 14:10:10 -04:00
Mayukha Vadari
09ef8595e7 refactor: move fixtures closer to tests (part 2) (#1561)
* move echo

* move fee

* move subscribe/unsubscribe

* move ledger_current

* move ledger_data

* move submit/submit_multisigned

* remove account_tx/account_offers/gateway_balances

* move account_info

* remove ledger_entry

* remove tx

* remove account_lines

* remove ripple_path_find

* remove ledger

* remove book_offers

* move ping

* remove global_config

* move test_command

* additional mock-rippled cleanup

* add explanatory comment to mock.addResponse
2021-10-04 14:10:10 -04:00
Mayukha Vadari
f9fe5936b1 refactor: rename all test files to camelCase (#1562)
* rename files to camelCase

* fix imports

* more renames

* pull all client tests out of individual folders

* fix imports

* fix tests
2021-10-04 14:10:10 -04:00
Jackson Mills
da9feffada Remove deprecated functions from api.ts (aka client.ts) (#1534)
* Removed deprecated functions from client.ts

* Renamed files to be camelCase

* Created top-level utils folder and tied all sub-references to it

* Grouped tests for those utils into their own section

Co-authored-by: Nathan Nichols <natenichols@cox.net>
2021-10-04 14:10:09 -04:00
Mayukha Vadari
8e52854773 fix: websocket wouldn't close properly on erroring test (#1554)
* fix: websocket wouldn't close properly on erroring test

* test: add test
2021-10-04 14:10:09 -04:00
Mayukha Vadari
5120b0fc83 refactor: moves fixtures closer to tests (#1551)
* modify account_info mocks

* move account_objects

* move server_info

* remove config (no longer needed)

* switch to simple dictionary instead of handlers

* fix rebase issues

* refactor: addResponse method on mock server object (#1555)

Co-authored-by: Elliot Lee <github.public@intelliot.com>
2021-10-04 14:10:09 -04:00
Mayukha Vadari
52f1789ecd Remove ledger methods from Connection (#1543)
* remove ledger subscription from connection

* remove more client ledger stuff

* resolve TS concerns

* fix all tests except broadcast tests

* fix broadcast tests

* clean up more ledger stuff in testing

* respond to comments
2021-10-04 14:10:09 -04:00
Mayukha Vadari
0b08de5956 Removes methods that were just rippled wrappers (#1550)
* remove getAccountInfo

* remove getAccountObjects

* remove getBalanceSheet (gateway_balances)

* remove getLedger

* remove getOrders (account_orders)

* remove getPaymentChannel (ledger_entry)

* remove getTransaction(s) (tx/account_tx)

* remove getSettings (account_info)

* remove getServerInfo (server_info)

* fix integ tests

* remove submit (also deprecated)

* fix integ tests

* add TODO
2021-10-04 14:10:09 -04:00
Mayukha Vadari
59396c3f8f Edit Client constructor to take a server URI (#1544)
* edit Client

* fix TS issues + tests

* minor edits

* rename ClientBroadcast -> BroadcastClient
2021-10-04 14:10:09 -04:00
Mayukha Vadari
f49b9d4b0e Rewrite XrplClient.request and general cleanup (#1519)
* first attempt at overloading

* fix TS issues

* improve connection typing

* more cleanup

* edit all ledger files

* more renames

* fix all other request calls

* clean up serverinfo

* fixes more request calls

* remove old legacy browser stuff

* remove unused types

* remove exports from objects

* add type to method signatures

* add ledger requests

* fix most tests

* comment out formatBidsAndAsks

* fix proxy test

* comment out failing tests

* move client-related files into client

* add payment channel requests

* fix imports

* remove finished TODOs

* fix tests

* fix integ tests

* remove exported types

* better ci
2021-10-04 14:10:09 -04:00
Mukul Jangid
478e147ae0 refactor: define typescript type for SetRegularKey transaction (#1548)
* refactor: define typescript type for SetRegularKey transaction
2021-10-04 14:10:09 -04:00
Nathan Nichols
d324056203 refactor: Define PaymentChannelFund transaction model (#1535)
refactor: Define PaymentChannelFund transaction model (#1535)
2021-10-04 14:10:09 -04:00
Nathan Nichols
db8f7c1bcb refactor: Define EscrowCreate transaction model (#1530)
refactor: Define EscrowCreate transaction model (#1530)
2021-10-04 14:10:09 -04:00
Nathan Nichols
4469d1cbf8 refactor: Define PaymentChannelClaim transaction model (#1536)
refactor: Define PaymentChannelClaim transaction model (#1536)
2021-10-04 14:10:08 -04:00
Nathan Nichols
05365a8690 refactor: Define PaymentChannelCreate transaction (#1533)
refactor: Define PaymentChannelCreate transaction model (#1533)
2021-10-04 14:10:08 -04:00
Omar Khan
f6b9878334 refactor: define TicketCreate transaction model (#1547)
- Defines a TypeScript type for TicketCreate
- Provides an optional function to users for verifying a TicketCreate instance at runtime: verifyTicketCreate()
- Adds tests for verifyTicketCreate()
2021-10-04 14:10:08 -04:00
Nathan Nichols
f68eb37565 refactor: Define EscrowFinish transaction model (#1531)
refactor: Define EscrowFinish transaction model (#1531)
2021-10-04 14:10:08 -04:00
Nathan Nichols
f95ffee0b0 refactor: define models for EscrowCancel (#1511)
refactor: define models for EscrowCancel (#1511)
2021-10-04 14:10:08 -04:00
Omar Khan
d5d996a92e refactor: define TrustSet transaction model (#1549)
- Defines a TypeScript type for TrustSet
- Provides an optional function to users for verifying a TrustSet instance at runtime: verifyTrustSet()
- Adds tests for verifyTrustSet()
2021-10-04 14:10:08 -04:00
Omar Khan
2ff0dde91d refactor: define DepositPreauth transaction model (#1545)
- Defines a TypeScript type for DepositPreauth
- Provides an optional function to users for verifying a DepositPreauth instance at runtime: verifyDepositPreauth()
- Adds tests for verifyDepositPreauth()
2021-10-04 14:10:08 -04:00
Omar Khan
bec487cf71 refactor: Define PaymentTransaction model (#1542)
- Defines a TypeScript type for PaymentTransaction
- Provides an optional function to users for verifying a PaymentTransaction instance at runtime: verifyPaymentTransaction()
- Adds tests for verifyPaymentTransaction()
- Adds isFlagEnabled() util to be used for models
2021-10-04 14:10:08 -04:00
Mukul Jangid
c1edab547a refactor: define typescript type for AccountDelete transaction (#1537)
* refactor: define typescript type for AccountDelete transaction
2021-10-04 14:10:08 -04:00
Mukul Jangid
fef5f858fd fix: resolve OfferCancel merge issues (#1546)
* fix: resolve OfferCancel git issues
2021-10-04 14:10:08 -04:00
Mukul Jangid
72f34d9388 refactor: define typescript type for AccountSet transaction (#1515)
* define typescript type for AccountSet transaction
2021-10-04 14:10:08 -04:00
Mukul Jangid
930d214107 refactor: define typescript types for OfferCancel Transaction Model (#1512)
* define typescript types for OfferCancel Transaction Model
2021-10-04 14:10:08 -04:00
Mukul Jangid
57c4d8be39 refactor: define SignerListSet model and tests (#1538)
* define typescript type for SignerListSet transaction
2021-10-04 14:10:08 -04:00
Mayukha Vadari
73109295b4 Rename RippleAPI client to Client (#1520)
* rename RippleAPI -> XrplClient

* more renames

* move API stuff to client folder

* rename all api -> client

* fix tests

* make tests run

* fix integ tests

* fix urls

* fix merge issues

* XrplClient -> Client

* fix merge issues

* rename xrpl-client npm symlink to xrpl-local
2021-10-04 14:10:08 -04:00
Mukul Jangid
6d08b9e12c refactor: define typescript types for CheckCash Transaction Model (#1522)
* Define Typescript types for CheckCash Transaction Model
2021-10-04 14:10:08 -04:00
Mukul Jangid
293f09d409 refactor: define typescript types for CheckCancel Transaction Model (#1526)
* offer

* accountroot

* amendments

* check

* deposit preauth

* directory node

* escrow

* fee settings

* ledger hashes

* negative unl

* pay channel

* ripple state

* signer list

* ticket

* export

* account_channels

* account_currencies

* account_info

* account_lines

* account_objects

* account_offers

* account_tx

* gateway_balances

* no ripple check

* respond to comments

* rename files to camelCase

* account_channels

* account_currencies

* account_info

* account_lines

* account_objects

* account_offers

* account_tx

* gateway_balances

* no ripple check

* respond to comments

* export methods

* fix typos

* refactor: Define type for CommonFields

* refactor: Define OfferCreate transaction type

* add a commented out SignedTransaction

* add tests for verifyCommonFields

* remove outdated files

* refactor: Define OfferCreate transaction

* define checkCancel model

* add tests

* fix: add tests and resolve conflicts

* fix: resolve typos and seperate out test

* fix: commenting issue

* refactor: add checkCreate to tx/index

Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
Co-authored-by: Nathan Nichols <natenichols@cox.net>
2021-10-04 14:10:08 -04:00
Mukul Jangid
f9bce29174 refactor: define typescript types for CheckCreate Transaction Model (#1524)
* feat: define checkCreate model

* test: add tests
2021-10-04 14:10:08 -04:00
Nathan Nichols
7fde5a2658 refactor: Define typescript definition for OfferCreate (#1508)
* refactor: Define OfferCreate transaction type
2021-10-04 14:10:08 -04:00
Nathan Nichols
d438430100 refactor: Add common transaction fields Typescript definition (#1507)
refactor: Add common transaction fields Typescript definition (#1507)
2021-10-04 14:10:08 -04:00
Omar Khan
c431e70900 define Wallet class (#1509)
* define Wallet class
- Wallet class is a utility for deriving a wallet composed of a keypair (publicKey/privateKey).
- A wallet can be derived from either a seed, mnemnoic, or entropy (array of random numbers).
- It provides functionality to sign/verify transactions offline.
2021-10-04 14:10:08 -04:00
Omar Khan
51b4ff7a2c define TypeScript types for Payment Channel methods (#1518)
add TypeScript type for payment channel methods
2021-10-04 14:10:08 -04:00
Jackson Mills
ec54841617 Added Ledger Method Interfaces (#1502)
Added request and response method interfaces for the api.
2021-10-04 14:10:08 -04:00
Mayukha Vadari
2166d8349e Implements TypeScript types for transaction method requests/responses (#1517)
* submit

* submit_multisigned

* transaction_entry

* tx

* export

* move searched_all to TxResponse
2021-10-04 14:10:08 -04:00
Mayukha Vadari
1ecd6a7e2a Implements TypeScript types for server info method requests/responses (#1514)
* fee

* manifest

* server_info

* server_state

* export

* fix amendment_blocked type

* fix typo
2021-10-04 14:10:07 -04:00
Mayukha Vadari
a0907472c9 Implements TypeScript types for utility method requests/responses (#1516)
* ping

* random

* export
2021-10-04 14:10:07 -04:00
Mayukha Vadari
57112c086c Implements TypeScript types for subscribe requests/responses/streams (#1510)
* subscribe

* streams

* unsubscribe

* exports

* fix merge issues

* respond to comments
2021-10-04 14:10:07 -04:00
Jackson Mills
b7f39e7225 Removed legacy exit code conversion (#1504) 2021-10-04 14:10:07 -04:00
Mayukha Vadari
f16876014c Implements TypeScript types for path and order book methods (#1503)
* book offers

* deposit authorized

* path_find

* ripple_path_find

* export

* fix typos

* fix issues

* respond to comments

* make `pathFind` id optional

* make source_currencies optional
2021-10-04 14:10:07 -04:00
Mayukha Vadari
68ac32fc06 Defines TypeScript types for rippled account method requests & responses (#1498)
* account_channels

* account_currencies

* account_info

* account_lines

* account_objects

* account_offers

* account_tx

* gateway_balances

* no ripple check

* respond to comments

* export methods

* fix typos

* respond to comments

* edit BaseResponse to be more specific
2021-10-04 14:10:07 -04:00
Mayukha Vadari
0886af33fd Defines TypeScript types for all ledger objects (#1499)
* offer

* accountroot

* amendments

* check

* deposit preauth

* directory node

* escrow

* fee settings

* ledger hashes

* negative unl

* pay channel

* ripple state

* signer list

* ticket

* export

* respond to comments

* rename files to camelCase
2021-10-04 14:10:07 -04:00
Elliot Lee
6e4868e6c7 Update repository.url (#1670) 2021-09-27 07:04:26 -07:00
Bharath Chari
718b0ac5a5 Update LICENSE (#1660) 2021-09-23 14:41:47 +03:00
29 changed files with 648 additions and 132 deletions

View File

@@ -1,6 +1,6 @@
ISC License
Copyright (c) 2012-2015 Ripple Labs Inc.
Copyright (c) 2012-2021 Contributers to xrpl.js
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above

View File

@@ -33,7 +33,7 @@ See also: [RippleAPI Beginners Guide](https://xrpl.org/get-started-with-rippleap
In an existing project (with `package.json`), install `xrpl.js`:
```
$ npm install xrpl
$ npm install xrpl@beta
```
Then see the [documentation](#documentation).
@@ -46,7 +46,7 @@ If you want to use `xrpl.js` with React Native you will need to have some of the
```shell
npm install react-native-crypto
npm install xrpl
npm install xrpl@beta
# install peer deps
npm install react-native-randombytes
# install latest rn-nodeify

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "xrpl",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "xrpl",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"license": "ISC",
"dependencies": {
"@types/lodash": "^4.14.136",

View File

@@ -1,6 +1,6 @@
{
"name": "xrpl",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [
@@ -79,14 +79,15 @@
"build:snippets": "tsc --build ./snippets/tsconfig.json",
"build:lib": "tsc --build tsconfig.build.json",
"build:web": "webpack",
"build:browserTests": "webpack --config ./test/webpack.config.js",
"analyze": "run-s build:web --analyze",
"watch": "run-s build:lib --watch",
"clean": "rm -rf dist",
"docgen": "typedoc ./src/index.ts",
"prepublish": "run-s clean build",
"prepublish": "npm run clean && npm run build",
"test": "nyc mocha --config=test/.mocharc.json --exit",
"test:integration": "TS_NODE_PROJECT=tsconfig.build.json nyc mocha ./test/integration/**/*.ts ./test/integration/*.ts",
"test:browser": "TS_NODE_PROJECT=tsconfig.build.json nyc mocha ./test/browser/*.ts",
"test:browser": "npm run build:browserTests && TS_NODE_PROJECT=tsconfig.build.json nyc mocha ./test/browser/*.ts",
"test:watch": "TS_NODE_PROJECT=src/tsconfig.json mocha --config=test/.mocharc.json --watch --reporter dot",
"format": "prettier --write '{src,test}/**/*.ts'",
"lint": "eslint . --ext .ts --max-warnings 0",
@@ -98,7 +99,7 @@
"prettier": "@xrplf/prettier-config",
"repository": {
"type": "git",
"url": "git://github.com/XRPLF/xrpl.js.git"
"url": "git@github.com:XRPLF/xrpl.js.git"
},
"readmeFilename": "README.md",
"engines": {

View File

@@ -216,6 +216,7 @@ export class Connection extends EventEmitter {
* @throws ConnectionError if there is a connection error, RippleError if there is already a WebSocket in existence.
*/
public async connect(): Promise<void> {
console.log('CONNECTING IN CONNECTION.CONNECT')
if (this.isConnected()) {
return Promise.resolve()
}
@@ -325,6 +326,7 @@ export class Connection extends EventEmitter {
if (!this.shouldBeConnected || this.ws == null) {
throw new NotConnectedError()
}
const [id, message, responsePromise] = this.requestManager.createRequest(
request,
timeout ?? this.config.timeout,

View File

@@ -164,7 +164,7 @@ const MAX_LIMIT = 400
class Client extends EventEmitter {
// New in > 0.21.0
// non-validated ledger versions are allowed, and passed to rippled as-is.
private readonly connection: Connection
public readonly connection: Connection
// Factor to multiply estimated fee by to provide a cushion in case the
// required fee rises during submission of a transaction. Defaults to 1.2.
@@ -182,6 +182,8 @@ class Client extends EventEmitter {
// eslint-disable-next-line max-lines-per-function -- okay because we have to set up all the connection handlers
public constructor(server: string, options: ClientOptions = {}) {
super()
console.log('CONSTRUCTING CLIENT')
if (typeof server !== 'string' || !/wss?(?:\+unix)?:\/\//u.exec(server)) {
throw new ValidationError(
'server URI must start with `wss://`, `ws://`, `wss+unix://`, or `ws+unix://`.',
@@ -241,15 +243,6 @@ class Client extends EventEmitter {
})
}
/**
* Get the URL of the server the Client is connected to.
*
* @returns The URL of the rippled server this Client is connected to.
*/
public get url(): string {
return this.connection.getUrl()
}
/**
* Returns true if there are more pages of data.
*
@@ -509,6 +502,8 @@ class Client extends EventEmitter {
* @returns A promise that resolves with a void value when a connection is established.
*/
public async connect(): Promise<void> {
console.log('CONNECTING IN CLIENT.CONNECT')
return this.connection.connect()
}

View File

@@ -127,6 +127,7 @@ async function setNextValidSequenceNumber(
const request: AccountInfoRequest = {
command: 'account_info',
account: tx.Account,
ledger_index: 'validated',
}
const data = await client.request(request)
// eslint-disable-next-line no-param-reassign, require-atomic-updates -- param reassign is safe with no race condition

View File

@@ -54,7 +54,7 @@ async function getOrderbook(
command: 'book_offers',
taker_pays: takerPays,
taker_gets: takerGets,
ledger_index: options.ledger_index,
ledger_index: options.ledger_index ?? 'validated',
ledger_hash: options.ledger_hash,
limit: options.limit ?? DEFAULT_LIMIT,
taker: options.taker,

View File

@@ -56,6 +56,17 @@ function isValidSecret(secret: string): boolean {
}
}
/**
* Validates that a given address is a valid X-Address or a valid classic
* address.
*
* @param address - Address to validate.
* @returns True if address is a valid X-Address or classic address.
*/
function isValidAddress(address: string): boolean {
return isValidXAddress(address) || isValidClassicAddress(address)
}
/**
* Removes undefined values from an object.
*
@@ -94,6 +105,7 @@ export {
rippleTimeToUnixTime,
unixTimeToRippleTime,
isValidSecret,
isValidAddress,
computeSignedTransactionHash,
computeBinaryTransactionSigningHash,
computeAccountRootIndex,

View File

@@ -36,7 +36,7 @@ const MAX_ATTEMPTS = 20
async function generateFaucetWallet(
this: Client,
wallet?: Wallet,
): Promise<Wallet | undefined> {
): Promise<Wallet> {
if (!this.isConnected()) {
throw new RippledError('Client not connected, cannot call faucet')
}
@@ -48,22 +48,22 @@ async function generateFaucetWallet(
: Wallet.generate()
// Create the POST request body
const postBody = new TextEncoder().encode(
JSON.stringify({
destination: fundWallet.classicAddress,
}),
)
// Retrieve the existing account balance
const addressToFundBalance = await getAddressXrpBalance(
this,
fundWallet.classicAddress,
const postBody = Buffer.from(
new TextEncoder().encode(
JSON.stringify({
destination: fundWallet.classicAddress,
}),
),
)
// Check the address balance is not undefined and is a number
const startingBalance =
addressToFundBalance && !Number.isNaN(Number(addressToFundBalance))
? Number(addressToFundBalance)
: 0
let startingBalance = 0
try {
startingBalance = Number(
await getAddressXrpBalance(this, fundWallet.classicAddress),
)
} catch {
/* startingBalance remains '0' */
}
// Options to pass to https.request
const options = getOptions(this, postBody)
@@ -77,8 +77,8 @@ async function returnPromise(
client: Client,
startingBalance: number,
fundWallet: Wallet,
postBody: Uint8Array,
): Promise<Wallet | undefined> {
postBody: Buffer,
): Promise<Wallet> {
return new Promise((resolve, reject) => {
const request = httpsRequest(options, (response) => {
const chunks: Uint8Array[] = []
@@ -127,7 +127,7 @@ async function onEnd(
client: Client,
startingBalance: number,
fundWallet: Wallet,
resolve: (wallet?: Wallet) => void,
resolve: (wallet: Wallet) => void,
reject: (err: ErrorConstructor | Error | unknown) => void,
): Promise<void> {
const body = Buffer.concat(chunks).toString()
@@ -161,7 +161,7 @@ async function processSuccessfulResponse(
body: string,
startingBalance: number,
fundWallet: Wallet,
resolve: (wallet?: Wallet) => void,
resolve: (wallet: Wallet) => void,
reject: (err: ErrorConstructor | Error | unknown) => void,
): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- We know this is safe and correct
@@ -212,13 +212,13 @@ async function getAddressXrpBalance(
): Promise<string> {
// Get all the account balances
try {
const balances = await client.getBalances(address)
const balances = await client.request({
command: 'account_info',
account: address,
ledger_index: 'validated',
})
// Retrieve the XRP balance
const xrpBalance = balances.filter(
(balance) => balance.currency.toUpperCase() === 'XRP',
)
return xrpBalance[0].value
return balances.result.account_data.Balance
} catch (err) {
if (err instanceof Error) {
throw new XRPLFaucetError(
@@ -254,7 +254,13 @@ async function hasAddressBalanceIncreased(
}
try {
const newBalance = Number(await getAddressXrpBalance(client, address))
let newBalance
try {
newBalance = Number(await getAddressXrpBalance(client, address))
} catch {
/* newBalance remains undefined */
}
if (newBalance > originalBalance) {
clearInterval(interval)
resolve(true)
@@ -279,9 +285,10 @@ async function hasAddressBalanceIncreased(
*
* @param client - Client.
* @returns A {@link FaucetNetwork}.
* @throws When the client url is not on altnet or devnet.
*/
function getFaucetUrl(client: Client): FaucetNetwork | undefined {
const connectionUrl = client.url
const connectionUrl = client.connection.getUrl()
// 'altnet' for Ripple Testnet server and 'testnet' for XRPL Labs Testnet server
if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) {
@@ -292,7 +299,7 @@ function getFaucetUrl(client: Client): FaucetNetwork | undefined {
return FaucetNetwork.Devnet
}
return undefined
throw new XRPLFaucetError('Faucet URL is not defined or inferrable.')
}
export default generateFaucetWallet

View File

@@ -3,17 +3,23 @@ import path from 'path'
import { expect, assert } from 'chai'
import puppeteer from 'puppeteer'
const TIMEOUT = 60000
describe('Browser Tests', function () {
this.timeout(TIMEOUT)
it('Integration Tests', async function () {
const browser = await puppeteer.launch({ headless: true })
try {
const page = await browser.newPage().catch()
page.setDefaultNavigationTimeout(0)
await page.goto(
path.join('file:///', __dirname, '../localIntegrationRunner.html'),
)
await page.waitForFunction(
'document.querySelector("body").innerText.includes("submit multisigned transaction")',
{ timeout: TIMEOUT },
)
const fails = await page.evaluate(() => {

View File

@@ -25,7 +25,8 @@ describe('Client', function () {
it('Client valid options', function () {
const client = new Client('wss://s:1')
const privateConnectionUrl = client.url
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: fix when src/client linting is merged
const privateConnectionUrl = (client.connection as any).url
assert.deepEqual(privateConnectionUrl, 'wss://s:1')
})

View File

@@ -15,7 +15,7 @@ describe('client constructor', function () {
it('Client valid options', function () {
const client = new Client('wss://s:1')
const privateConnectionUrl = client.url
const privateConnectionUrl = client.connection.getUrl()
assert.deepEqual(privateConnectionUrl, 'wss://s:1')
})

View File

@@ -0,0 +1,65 @@
import assert from 'assert'
import _ from 'lodash'
import { Client, isValidClassicAddress, isValidXAddress } from 'xrpl-local'
// how long before each test case times out
const TIMEOUT = 60000
// This test is reliant on external networks, and as such may be flaky.
describe('generateFaucetWallet', function () {
this.timeout(TIMEOUT)
it('submit generates a testnet wallet', async function () {
const api = new Client('wss://s.altnet.rippletest.net:51233')
await api.connect()
const wallet = await api.generateFaucetWallet()
assert.notEqual(wallet, undefined)
assert(isValidClassicAddress(wallet.classicAddress))
assert(isValidXAddress(wallet.getXAddress()))
const info = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(info.result.account_data.Balance, '1000000000')
await api.generateFaucetWallet(wallet)
const afterSent = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(afterSent.result.account_data.Balance, '2000000000')
await api.disconnect()
})
it('submit generates a devnet wallet', async function () {
const api = new Client('wss://s.devnet.rippletest.net:51233')
await api.connect()
const wallet = await api.generateFaucetWallet()
assert.notEqual(wallet, undefined)
assert(isValidClassicAddress(wallet.classicAddress))
assert(isValidXAddress(wallet.getXAddress()))
const info = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(info.result.account_data.Balance, '1000000000')
await api.generateFaucetWallet(wallet)
const afterSent = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(afterSent.result.account_data.Balance, '2000000000')
await api.disconnect()
})
})

View File

@@ -36,4 +36,6 @@ export * from './requests/ripplePathFind'
export * from './requests/submit'
export * from './requests/tx'
export * from './requests/utility'
export * from './generateFaucetWallet'
export * from './integration'

View File

@@ -0,0 +1,56 @@
import { assert } from 'chai'
import _ from 'lodash'
import { FeeRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('fee', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: FeeRequest = {
command: 'fee',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
current_ledger_size: '0',
current_queue_size: '0',
drops: {
base_fee: '10',
median_fee: '5000',
minimum_fee: '10',
open_ledger_fee: '10',
},
expected_ledger_size: '1000',
ledger_current_index: 2925,
levels: {
median_level: '128000',
minimum_level: '256',
open_ledger_level: '256',
reference_level: '256',
},
max_queue_size: '20000',
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.ledger_current_index, 'number')
assert.deepEqual(
_.omit(response.result, ['ledger_current_index']),
_.omit(expected.result, ['ledger_current_index']),
)
})
})

View File

@@ -0,0 +1,136 @@
import { assert } from 'chai'
import _ from 'lodash'
import { ServerInfoRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('server_info', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: ServerInfoRequest = {
command: 'server_info',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
info: {
build_version: '1.7.3',
complete_ledgers: '2563-2928',
hostid: '44578fe64241',
io_latency_ms: 1,
jq_trans_overflow: '0',
last_close: { converge_time_s: 0.1, proposers: 0 },
load: {
job_types: [
{
in_progress: 1,
job_type: 'clientCommand',
peak_time: 4,
per_second: 9,
},
{ job_type: 'updatePaths', per_second: 1 },
{ job_type: 'advanceLedger', per_second: 1 },
{ job_type: 'pathFind', per_second: 1 },
{ job_type: 'WriteNode', per_second: 17 },
],
threads: 1,
},
load_factor: 1,
peer_disconnects: '0',
peer_disconnects_resources: '0',
peers: 0,
pubkey_node: 'n9K6DaaReKkCjb9sEfXh5xP3BV9JisrJ9biKB3CSSFXancBnv5cW',
pubkey_validator: 'none',
server_state: 'full',
server_state_duration_us: '8752395105',
state_accounting: {
connected: { duration_us: '0', transitions: 0 },
disconnected: { duration_us: '41860', transitions: 1 },
full: { duration_us: '20723121268', transitions: 1 },
syncing: { duration_us: '0', transitions: 0 },
tracking: { duration_us: '0', transitions: 0 },
},
time: '2021-Sep-23 22:56:55.320858 UTC',
uptime: 8752,
validated_ledger: {
age: 0,
base_fee_xrp: 0.00001,
hash: '532175EC25CF34081D7F83584F37DAB70035A422CBE94352BEDA8EC123CB8F60',
reserve_base_xrp: 200,
reserve_inc_xrp: 50,
seq: 1906,
},
validation_quorum: 0,
validator_list: {
count: 0,
expiration: 'unknown',
status: 'unknown',
},
},
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.info.time, 'string')
assert.equal(typeof response.result.info.uptime, 'number')
assert.equal(typeof response.result.info.complete_ledgers, 'string')
assert.equal(typeof response.result.info.hostid, 'string')
assert.equal(typeof response.result.info.pubkey_node, 'string')
assert.equal(typeof response.result.info.server_state_duration_us, 'string')
const removeKeys = [
'time',
'uptime',
'complete_ledgers',
'hostid',
'load',
'state_accounting',
'pubkey_node',
'server_state_duration_us',
'validated_ledger',
]
assert.deepEqual(
_.omit(response.result.info, removeKeys),
_.omit(expected.result.info, removeKeys),
)
// load
assert.equal(typeof response.result.info.load.threads, 'number')
for (const obj of response.result.info.load.job_types) {
assert.equal(typeof obj.per_second, 'number')
assert.equal(typeof obj.job_type, 'string')
}
// state_accounting
Object.keys(response.result.info.state_accounting).forEach(function (key) {
assert.equal(
typeof response.result.info.state_accounting[key].duration_us,
'string',
)
assert.equal(
typeof response.result.info.state_accounting[key].transitions,
'number',
)
})
// validated_ledger
assert.equal(typeof response.result.info.validated_ledger.hash, 'string')
for (const key of Object.keys(
_.omit(response.result.info.validated_ledger, 'hash'),
)) {
assert.equal(typeof response.result.info.validated_ledger[key], 'number')
}
})
})

View File

@@ -0,0 +1,141 @@
import { assert } from 'chai'
import _ from 'lodash'
import { ServerStateRequest } from 'xrpl-local'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
// how long before each test case times out
const TIMEOUT = 20000
describe('server_state', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const request: ServerStateRequest = {
command: 'server_state',
}
const response = await this.client.request(request)
const expected = {
id: 0,
result: {
state: {
build_version: '1.7.3',
complete_ledgers: '2563-2932',
io_latency_ms: 1,
jq_trans_overflow: '0',
last_close: {
converge_time: 100,
proposers: 0,
},
load: {
job_types: [
{
in_progress: 1,
job_type: 'clientCommand',
peak_time: 4,
per_second: 9,
},
{ job_type: 'updatePaths', per_second: 1 },
{ job_type: 'advanceLedger', per_second: 1 },
{ job_type: 'pathFind', per_second: 1 },
{ job_type: 'WriteNode', per_second: 17 },
],
threads: 1,
},
load_base: 256,
load_factor: 256,
load_factor_fee_escalation: 256,
load_factor_fee_queue: 256,
load_factor_fee_reference: 256,
load_factor_server: 256,
peer_disconnects: '0',
peer_disconnects_resources: '0',
peers: 0,
pubkey_node: 'n9K6DaaReKkCjb9sEfXh5xP3BV9JisrJ9biKB3CSSFXancBnv5cW',
pubkey_validator: 'none',
server_state: 'full',
server_state_duration_us: '8752487389',
state_accounting: {
connected: { duration_us: '0', transitions: 0 },
disconnected: { duration_us: '41860', transitions: 1 },
full: { duration_us: '20723121268', transitions: 1 },
syncing: { duration_us: '0', transitions: 0 },
tracking: { duration_us: '0', transitions: 0 },
},
time: '2021-Sep-23 22:56:55.413151 UTC',
uptime: 8752,
validated_ledger: {
base_fee: 10,
close_time: 685829741,
hash: 'B98AABCE40A54DF654C86E56088AD7D46BBA8B8E93AD3FAC2426FEFF847F7937',
reserve_base: 200000000,
reserve_inc: 50000000,
seq: 2294,
},
validation_quorum: 0,
validator_list_expires: 0,
},
},
status: 'success',
type: 'response',
}
assert.equal(response.status, expected.status)
assert.equal(response.type, expected.type)
assert.equal(typeof response.result.state.complete_ledgers, 'string')
assert.equal(typeof response.result.state.pubkey_node, 'string')
assert.equal(typeof response.result.state.time, 'string')
assert.equal(typeof response.result.state.uptime, 'number')
assert.equal(
typeof response.result.state.server_state_duration_us,
'string',
)
const removeKeys = [
'complete_ledgers',
'load',
'state_accounting',
'pubkey_node',
'time',
'uptime',
'server_state_duration_us',
'validated_ledger',
]
assert.deepEqual(
_.omit(response.result.state, removeKeys),
_.omit(expected.result.state, removeKeys),
)
// load
assert.equal(typeof response.result.state.load.threads, 'number')
for (const obj of response.result.state.load.job_types) {
assert.equal(typeof obj.per_second, 'number')
assert.equal(typeof obj.job_type, 'string')
}
// state_accounting
Object.keys(response.result.state.state_accounting).forEach(function (key) {
assert.equal(
typeof response.result.state.state_accounting[key].duration_us,
'string',
)
assert.equal(
typeof response.result.state.state_accounting[key].transitions,
'number',
)
})
// validated_ledger
assert.equal(typeof response.result.state.validated_ledger.hash, 'string')
for (const key of Object.keys(
_.omit(response.result.state.validated_ledger, 'hash'),
)) {
assert.equal(typeof response.result.state.validated_ledger[key], 'number')
}
})
})

View File

@@ -0,0 +1,35 @@
import _ from 'lodash'
import { AccountDelete } from 'xrpl-local/models/transactions'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
import { generateFundedWallet, ledgerAccept, testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('AccountDelete', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const wallet2 = await generateFundedWallet(this.client)
// to the satisfy the condition that account sequence and current ledger_index should be 256 apart.
const promises: Array<Promise<void>> = []
for (let iter = 0; iter < 256; iter += 1) {
promises.push(ledgerAccept(this.client))
}
await Promise.all(promises)
const tx: AccountDelete = {
TransactionType: 'AccountDelete',
Account: this.wallet.getClassicAddress(),
Destination: wallet2.getClassicAddress(),
}
await testTransaction(this.client, tx, this.wallet)
})
})

View File

@@ -0,0 +1,26 @@
import _ from 'lodash'
import { AccountSet } from 'xrpl-local/models/transactions'
import serverUrl from '../serverUrl'
import { setupClient, suiteClientSetup, teardownClient } from '../setup'
import { testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('AccountSet', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('base', async function () {
const tx: AccountSet = {
TransactionType: 'AccountSet',
Account: this.wallet.getClassicAddress(),
}
await testTransaction(this.client, tx, this.wallet)
})
})

View File

@@ -13,7 +13,7 @@ import { generateFundedWallet, testTransaction } from '../utils'
// how long before each test case times out
const TIMEOUT = 20000
describe('PaymentChannelFund', function () {
describe('PaymentChannelClaim', function () {
this.timeout(TIMEOUT)
before(suiteClientSetup)

View File

@@ -35,7 +35,6 @@ describe('PaymentChannelFund', function () {
this.wallet,
paymentChannelCreate,
)
await testTransaction(this.client, paymentChannelCreate, this.wallet)
const paymentChannelFund: PaymentChannelFund = {

View File

@@ -11,7 +11,7 @@ const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
export async function ledgerAccept(client: Client): Promise<void> {
const request = { command: 'ledger_accept' }
await client.request(request)
await client.connection.request(request)
}
export async function fundAccount(
@@ -83,6 +83,9 @@ export async function testTransaction(
transaction: Transaction,
wallet: Wallet,
): Promise<void> {
// Accept any un-validated changes.
await ledgerAccept(client)
// sign/submit the transaction
const response = await client.submitTransaction(wallet, transaction)

View File

@@ -17,7 +17,7 @@
mocha.ui('bdd')
</script>
<script src="../testCompiledForWeb/index.js"></script>
<script src="./testCompiledForWeb/index.js"></script>
<script>
mocha.run()

View File

@@ -12,7 +12,7 @@ async function setupClient(this: any, port = defaultPort): Promise<void> {
return tclient
.connect()
.then(async () => {
return tclient.request({
return tclient.connection.request({
command: 'test_command',
data: { openOnOtherPort: true },
})

View File

@@ -0,0 +1,25 @@
import { assert } from 'chai'
import { isValidAddress } from 'xrpl-local'
describe('isValidAddress', function () {
it('Validates valid classic address', function () {
const classic = 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W'
assert(isValidAddress(classic))
})
it('Does not validate invalid classic address', function () {
const classic = 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENhqw96W'
assert(!isValidAddress(classic))
})
it('Validates valid X-Address', function () {
const xAddress = 'XV5sbjUmgPpvXv4ixFWZ5ptAYZ6PD28Sq49uo34VyjnmK5H'
assert(isValidAddress(xAddress))
})
it('Does not validate invalid X-Address', function () {
const xAddress = 'XV5sbjUmgPpvXv4ixFWZ5pfAYZ6PD28Sq49uo34VyjnmK5H'
assert(!isValidAddress(xAddress))
})
})

View File

@@ -32,6 +32,6 @@ describe('Get Faucet URL', function () {
it('returns undefined if not a Testnet or Devnet server URL', function () {
// Info: setupClient.setup creates a connection to 'localhost'
assert.strictEqual(getFaucetUrl(this.client), undefined)
assert.throws(() => getFaucetUrl(this.client))
})
})

79
test/webpack.config.js Normal file
View File

@@ -0,0 +1,79 @@
'use strict'
const path = require('path')
const webpack = require('webpack')
const assert = require('assert')
function webpackForTest(testFileName) {
const match = testFileName.match(/\/?([^\/]*)\.ts$/)
if (!match) {
assert(false, 'wrong filename:' + testFileName)
}
const test = {
mode: 'production',
cache: true,
externals: [
{
'xrpl-local': 'xrpl',
net: 'null',
},
],
entry: testFileName,
output: {
library: match[1].replace(/-/g, '_'),
path: path.join(__dirname, './testCompiledForWeb/'),
filename: match[1] + '.js',
},
plugins: [
new webpack.ProvidePlugin({ process: 'process/browser' }),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
],
module: {
rules: [
{
test: /jayson/,
use: 'null',
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
composite: false,
declaration: false,
declarationMap: false,
},
},
},
],
},
],
},
node: {
global: true,
__filename: false,
__dirname: true,
},
resolve: {
alias: {
ws: './dist/npm/client/wsWrapper.js',
'https-proxy-agent': false,
},
extensions: ['.ts', '.js', '.json'],
fallback: {
buffer: require.resolve('buffer/'),
assert: require.resolve('assert/'),
url: require.resolve('url/'),
stream: require.resolve('stream-browserify'),
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
http: require.resolve('stream-http'),
},
},
}
return test
}
module.exports = [(env, argv) => webpackForTest('./test/integration/index.ts')]

View File

@@ -1,8 +1,6 @@
'use strict'
const path = require('path')
const fs = require('fs')
const webpack = require('webpack')
const assert = require('assert')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
function getDefaultConfiguration() {
@@ -51,79 +49,6 @@ function getDefaultConfiguration() {
}
}
function webpackForTest(testFileName) {
const match = testFileName.match(/\/?([^\/]*)\.ts$/)
if (!match) {
assert(false, 'wrong filename:' + testFileName)
}
const test = {
mode: 'production',
cache: true,
externals: [
{
'xrpl-local': 'xrpl',
net: 'null',
},
],
entry: testFileName,
output: {
library: match[1].replace(/-/g, '_'),
path: path.join(__dirname, './testCompiledForWeb/'),
filename: match[1] + '.js',
},
plugins: [
new webpack.ProvidePlugin({ process: 'process/browser' }),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
],
module: {
rules: [
{
test: /jayson/,
use: 'null',
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
composite: false,
declaration: false,
declarationMap: false,
},
},
},
],
},
],
},
node: {
global: true,
__filename: false,
__dirname: true,
},
resolve: {
alias: {
ws: './dist/npm/client/wsWrapper.js',
'https-proxy-agent': false,
},
extensions: ['.ts', '.js', '.json'],
fallback: {
buffer: require.resolve('buffer/'),
assert: require.resolve('assert/'),
url: require.resolve('url/'),
stream: require.resolve('stream-browserify'),
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
http: require.resolve('stream-http'),
},
},
}
return test
}
module.exports = [
(env, argv) => {
const config = getDefaultConfiguration()
@@ -140,5 +65,4 @@ module.exports = [
}
return config
},
(env, argv) => webpackForTest('./test/integration/index.ts'),
]