13 KiB
Contributing
High Level Process to Contribute Code
- You should open a PR against
mainand ensure that all CI passes. - Your changes should have unit and/or integration tests.
- Your changes should pass the linter.
- You should get a full code review from two of the maintainers.
- Then you can merge your changes. (Which will then be included in the next release)
Set up your dev environment
Requirements
We use Node v18 for development - that is the version that our linters require.
You must also use npm v7. You can check your npm version with:
npm -v
If your npm version is too old, use this command to update it:
npm -g i npm@7
Set up
- Clone the repository
cdinto the repository- Install dependencies with
npm install
Build
npm run build
Run the linter
npm install
npm run build
npm run lint
Running Tests
For integration and browser tests, we use a rippled node in standalone mode to test xrpl.js code against. To set this up, you can either configure and run rippled locally, or set up the Docker container rippleci/rippled by following these instructions. The latter will require you to install Docker.
Unit Tests
npm install
npm run build
npm test
Integration Tests
From the top-level xrpl.js folder (one level above packages), run the following commands:
npm install
# sets up the rippled standalone Docker container - you can skip this step if you already have it set up
docker run -p 6006:6006 --rm -it --name rippled_standalone --volume $PWD/.ci-config:/etc/opt/ripple/ --entrypoint bash rippleci/rippled:develop -c 'rippled -a'
npm run build
npm run test:integration
Breaking down the command:
docker run -p 6006:6006starts a Docker container with an open port for admin WebSocket requests.--rmtells docker to close the container after processes are done running.-itallows you to interact with the container.--name rippled_standaloneis an instance name for clarity--volume $PWD/.ci-config:/etc/opt/ripple/identifies therippled.cfgandvalidators.txtto import. It must be an absolute path, so we use$PWDinstead of./.rippleci/rippledis an image that is regularly updated with the latestrippledreleases--entrypoint bash rippleci/rippled:developmanually overrides the entrypoint (for the latest version of rippled on thedevelopbranch)-c 'rippled -a'provides the bash command to startrippledin standalone mode from the manual entrypoint
Browser Tests
There are two ways to run browser tests.
One is in the browser - run npm run build:browserTests and open test/localIntegrationRunner.html in your browser.
The other is in the command line (this is what we use for CI) -
This should be run from the xrpl.js top level folder (one above the packages folder).
npm run build
# sets up the rippled standalone Docker container - you can skip this step if you already have it set up
docker run -p 6006:6006 --rm -it --name rippled_standalone --volume $PWD/.ci-config:/etc/opt/ripple/ --entrypoint bash rippleci/rippled:develop -c 'rippled -a'
npm run test:browser
High Level Architecture
This is a monorepo, which means that there are multiple packages in a single GitHub repository using Lerna.
The 4 packages currently here are:
- xrpl.js - The client library for interacting with the ledger.
- ripple-binary-codec - A library for serializing and deserializing transactions for the ledger.
- ripple-keypairs - A library for generating and using cryptographic keypairs.
- ripple-address-codec - A library for encoding and decoding XRP Ledger addresses and seeds.
- isomorphic - A collection of isomorphic implementations of crypto and utility functions.
- secret-numbers - Generate XRPL Accounts with a number-based secret: 8 chunks of 6 digits.
Each package has it's own README which dives deeper into what it's main purpose is, and the core functionality it offers. They also run tests independently as they were originally in separate repositories.
These are managed in a monorepo because often a change in a lower-level library will also require a change in xrpl.js, and so it makes sense to be able to allow for modifications of all packages at once without coordinating versions across multiple repositories.
Let's dive a bit into how xrpl.js is structured!
The File Structure
Within the xrpl package, each folder has a specific purpose:
Client - This contains logic for handling the websocket connection to rippled servers.
Models - These types model LedgerObjects, Requests/Methods, and Transactions in order to give type hints and nice errors for users.
Sugar - This is where handy helper functions end up, like submit, autofill, and getXRPBalance amongst others.
Utils - These are shared functions which are useful for conversions, or internal implementation details within the library.
Wallet - This logic handles managing keys, addresses, and signing within xrpl.js
Writing Tests for xrpl.js
For every file in src, we try to have a corresponding file in test with unit tests.
The goal is to maintain above 80% code coverage, and generally any new feature or bug fix should be accompanied by unit tests, and integration tests if applicable.
For an example of a unit test, check out the autofill tests here.
If your code connects to the ledger (ex. Adding a new transaction type) it's handy to write integration tests to ensure that you can successfully interact with the ledger. Integration tests are generally run against a docker instance of rippled which contains the latest updates. Since standalone mode allows us to manually close ledgers, this allows us to run integration tests at a much faster rate than if we had to wait 4-5 seconds per transaction for the ledger to validate the transaction. See above for how to start up the docker container to run integration tests.
All integration tests should be written in the test/integration folder, with new Requests and Transactions tests being in their respective folders.
For an example of how to write an integration test for xrpl.js, you can look at the Payment integration test.
Generate reference docs
You can see the complete reference documentation at xrpl.js docs. You can also generate them locally using typedoc:
npm run docgen
This updates docs/ at the top level, where GitHub Pages looks for the docs.
Update definitions.json
Use this repo to generate a new definitions.json file from the rippled source code. Instructions are available in that README.
Adding and removing packages
xrpl.js uses lerna and npm's workspaces features to manage a monorepo.
Adding and removing packages requires a slightly different process than normal
as a result.
Adding or removing development dependencies
xrpl.js strives to use the same development dependencies in all packages.
You may add and remove dev dependencies like normal:
### adding a new dependency
npm install --save-dev abbrev
### removing a dependency
npm uninstall --save-dev abbrev
Adding or removing runtime dependencies
You need to specify which package is changing using the -w flag:
### adding a new dependency to `xrpl`
npm install abbrev -w xrpl
### adding a new dependency to `ripple-keypairs`
npm install abbrev -w ripple-keypairs
### removing a dependency
npm uninstall abbrev -w xrpl
Updating the Docker container for CI
In order to test the library, we need to enable the latest amendments in the docker container.
This requires updating the /.ci-config/rippled.cfg file with the hashes and names of new amendments.
In order to update the list, follow these steps from the top level of the library:
- Run
node ./.ci-config/getNewAmendments.js - If there are any new amendment hashes, add a comment to the end of
/.ci-config/rippled.cfgwith the dateEx. "# Added August 9th, 2023"
- For each hash printed out by the script, add the hash and name to the config file.
- Ex.
B2A4DB846F0891BF2C76AB2F2ACC8F5B4EC64437135C6E56F3F859DE5FFD5856 ExpandedSignerList - You can look up the name by searching for the hash on https://xrpl.org/known-amendments.html
- Ex.
- Push your changes
Note: The same updated config can be used to update xrpl-py's CI as well.
Updating definitions.json
This should almost always be done using the xrpl-codec-gen script - if the output needs manual intervention afterwards, consider updating the script instead.
- Clone / pull the latest changes from rippled - Specifically the
developbranch is usually the right one. - Clone / pull the latest changes from
xrpl-codec-gen - From the
xrpl-codec-gentool, follow the steps in theREADME.mdto generate a newdefinitions.jsonfile. - Replace the
definitions.jsonfile in theripple-binary-codecwith the newly generated file. - Verify that the changes make sense by inspection before submitting, as there may be updates required for the
xrpl-codec-gentool depending on the latest amendments we're updating to match.
Release process + checklist
PR process
- Your changes should be on a branch.
- Your changes should have unit tests.
- Lint the code with
npm lint - Build your code with
npm build - Run the unit tests with
npm test - Get a full code review.
- Merge your branch into
mainand push to github. - Ensure that all tests passed on the last CI that ran on
main.
Release
-
Checkout
main(or your beta branch) andgit pull. -
Create a new branch (
git checkout -b <BRANCH_NAME>) to capture updates that take place during this process. -
Update
HISTORY.mdto reflect release changes.- Update the version number and release date, and ensure it lists the changes since the previous release.
-
Run
npm run docgenif the docs were modified in this release to update them (skip this step for a beta). -
Run
npm run buildto triple check the build still works -
Run
npx lerna version --no-git-tag-version- This bumps the package versions.- For each changed package, pick what the new version should be. Lerna will bump the versions, commit version bumps to
main, and create a new git tag for each published package. - If you do NOT want to update the package number, choose "Custom Version" and set the version to be the same as the existing version. Lerna will not publish any changes in this case.
- If publishing a beta, make sure that the versions are all of the form
a.b.c-beta.d, wherea,b, andcare identical to the last normal release except for one, which has been incremented by 1.
- For each changed package, pick what the new version should be. Lerna will bump the versions, commit version bumps to
-
Run
npm ito update the package-lock with the updated versions. -
Create a new PR from this branch into
mainand merge it (you can directly merge into the beta branch for a beta). -
Checkout
mainandgit pull(you can skip this step for a beta since you already have the latest version of the beta branch). -
Actually publish the packages with one of the following:
- Stable release: Run
npx lerna publish from-package --yes - Beta release: Run
npx lerna publish from-package --dist-tag beta --yesNotice this allows developers to install the package withnpm add xrpl@beta
- Stable release: Run
-
If requested, enter your npmjs.com OTP (one-time password) to complete publication.
NOW YOU HAVE PUBLISHED! But you're not done; we have to notify people!
-
Run
git tag <tagname> -m <tagname>, where<tagname>is the new package and version (e.g.xrpl@2.1.1), for each version released. -
Run
git push --follow-tags, to push the tags to Github. -
On GitHub, click the "Releases" link on the right-hand side of the page.
-
Repeat for each release:
- Click "Draft a new release"
- Click "Choose a tag", and choose a tag that you just created.
- Edit the name of the release to match the tag (IE <package>@<version>) and edit the description as you see fit.
-
Send an email to xrpl-announce.
-
Lastly, send a similar message to the XRPL Discord in the
javascriptchannel. The message should include:- The version changes for xrpl libraries
- A link to the more detailed changes
- Highlights of important changes
Mailing Lists
We have a low-traffic mailing list for announcements of new xrpl.js releases. (About 1 email every couple of weeks)
If you're using the XRP Ledger in production, you should run a rippled server and subscribe to the ripple-server mailing list as well.