Reorganize repository in preparation for more programs (#20)

* Initial reorg

* Update READMEs

* Update CI

* Add CI build stages
This commit is contained in:
Tyera Eulberg 2020-06-05 12:34:17 -06:00 committed by GitHub
parent 299025b479
commit dfbfc9367b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 215 additions and 116 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
bin

View File

@ -12,6 +12,7 @@ notifications:
install:
- cargo --version
- rustup install nightly
- docker --version
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
- sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main"
@ -23,10 +24,10 @@ install:
- clang-7 --version
- nvm install node
- node --version
script:
- npm install --prefix token
- npm run build:program --prefix token
- npm run test --prefix token
- npm run cluster:devnet --prefix token
- npm run start --prefix token
- ./do.sh update
jobs:
include:
- stage: "Test Programs"
script: ./ci/build-test-all.sh
- script: ./ci/token.sh

View File

@ -11,3 +11,46 @@ These programs are tested against [Solana](https://solana.com)'s implementation
of Sealevel, solana-runtime, and deployed to its mainnet. As others implement
Sealevel, we will graciously accept patches to ensure the programs here are
portable across all implementations.
## Building
These programs cannot be built directly via cargo and instead require the build scripts located in Solana's BPF-SDK.
Download or update the BPF-SDK by running:
```bash
$ ./do.sh update
```
To build all programs, run:
```bash
$ ./do.sh build
```
Or choose a specific program:
```bash
$ ./do.sh build <program>
```
## Testing
Unit tests contained within all projects can be built via:
```bash
$ ./do.sh test
```
Or:
```bash
$ ./do.sh test <program>
```
## Clippy
Clippy is also supported via:
```bash
$ ./do.sh clippy
```
Or:
```
$ ./do.sh clippy <program>
```

22
bpf-sdk-install.sh Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
installDir=$1
channel=edge
if [[ -n $2 ]]; then
channel=$2
fi
echo "Installing $channel BPF SDK into $installDir"
set -x
cd "$installDir/"
curl -L --retry 5 --retry-delay 2 -o bpf-sdk.tar.bz2 \
http://solana-sdk.s3.amazonaws.com/"$channel"/bpf-sdk.tar.bz2
rm -rf bpf-sdk
mkdir -p bpf-sdk
tar jxf bpf-sdk.tar.bz2
rm -f bpf-sdk.tar.bz2
cat bpf-sdk/version.txt

8
ci/build-test-all.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
cd "$(dirname "$0")/.."
set -e
./do.sh build
./do.sh test

11
ci/token.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
cd "$(dirname "$0")/../token/js"
set -e
npm install
npm run build:program
npm run test
npm run cluster:devnet
npm run start

View File

@ -5,7 +5,7 @@ cd "$(dirname "$0")"
usage() {
cat <<EOF
Usage: do.sh action
Usage: do.sh <action> <project>
Supported actions:
build
@ -17,49 +17,64 @@ Supported actions:
EOF
}
sdkDir=../../node_modules/@solana/web3.js/bpf-sdk
targetDir="$PWD"/target
sdkParentDir=bin
sdkDir="$sdkParentDir"/bpf-sdk
targetDir="$PWD"/"$2"/target
profile=bpfel-unknown-unknown/release
perform_action() {
set -e
case "$1" in
build)
"$sdkDir"/rust/build.sh "$PWD"
"$sdkDir"/rust/build.sh "$2"
so_path="$targetDir/$profile"
so_name="spl_token"
so_name="spl_${3%/}"
if [ -f "$so_path/${so_name}.so" ]; then
cp "$so_path/${so_name}.so" "$so_path/${so_name}_debug.so"
"$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/$so_name.so"
fi
;;
clean)
"$sdkDir"/rust/clean.sh "$PWD"
"$sdkDir"/rust/clean.sh "$2"
;;
test)
echo "test"
shift
cargo +nightly test $@
(
cd "$2"
echo "test $2"
cargo +nightly test
)
;;
clippy)
echo "clippy"
cargo +nightly clippy
(
cd "$2"
echo "clippy $2"
cargo +nightly clippy
)
;;
fmt)
echo "formatting"
cargo fmt
(
cd "$2"
echo "formatting $2"
cargo fmt
)
;;
update)
mkdir -p $sdkParentDir
./bpf-sdk-install.sh $sdkParentDir
;;
dump)
# Dump depends on tools that are not installed by default and must be installed manually
# - greadelf
# - rustfilt
(
download_bpf_sdk
pwd
"$0" build
"$0" build "$3"
cd "$3"
so_path="$targetDir/$profile"
so_name="solana_bpf_token"
so_name="solana_bpf_${3%/}"
so="$so_path/${so_name}_debug.so"
dump="$so_path/${so_name}-dump"
@ -102,4 +117,19 @@ perform_action() {
set -e
perform_action "$@"
if [[ "$#" -ne 2 ]]; then
if [[ $1 == "update" ]]; then
perform_action "$1"
else
# Build all projects
for project in */; do
if [[ ${project%/} == @($sdkParentDir|ci|target) ]]; then
continue;
fi
perform_action "$1" "$PWD/$project" "$project"
done
fi
else
# Build requested project
perform_action "$1" "$PWD/$2" "$2"
fi

1
token/.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules
.env
/target/

View File

@ -14,7 +14,7 @@ edition = "2018"
num-derive = "0.2"
num-traits = "0.2"
solana-sdk = { version = "=1.2.0", default-features = false, features=["program"] }
solana-sdk-bpf-test = { path = "../../node_modules/@solana/web3.js/bpf-sdk/rust/test", default-features = false }
solana-sdk-bpf-test = { path = "../bin/bpf-sdk/rust/test", default-features = false }
thiserror = "1.0"
[lib]

View File

@ -2,62 +2,7 @@
An ERC20-like Token program on the Solana blockchain.
The project comprises of:
The project comprises:
* A library to interact with the on-chain program
* Client that exercises the program
## Getting Started
First fetch the npm dependencies, including `@solana/web3.js`, by running:
```sh
$ npm install
```
### Select a Network
The client connects to a local Solana cluster by default.
To enable on-chain program logs, set the `RUST_LOG` environment variable:
```bash
$ export RUST_LOG=solana_runtime::native_loader=trace,solana_runtime::system_instruction_processor=trace,solana_runtime::bank=debug,solana_bpf_loader=debug,solana_rbpf=debug
```
To start a local Solana cluster run:
```bash
$ npm run localnet:update
$ npm run localnet:up
```
Solana cluster logs are available with:
```bash
$ npm run localnet:logs
```
For more details on working with a local cluster, see the [full instructions](https://github.com/solana-labs/solana-web3.js#local-network).
### Run the test client
```sh
$ npm run start
```
## Pointing to a public Solana cluster
Solana maintains three public clusters:
- `devnet` - Development cluster with airdrops enabled
- `testnet` - Tour De Sol test cluster without airdrops enabled
- `mainnet-beta` - Main cluster
Use npm scripts to configure which cluster.
To point to `devnet`:
```bash
$ npm run cluster:devnet
```
To point back to the local cluster:
```bash
$ npm run cluster:localnet
```
* The Rust on-chain program
* A JavaScript library to interact with the on-chain program

62
token/js/README.md Normal file
View File

@ -0,0 +1,62 @@
# Token Javascript API
The Token JavaScript library comprises:
* A library to interact with the on-chain program
* A test client that exercises the program
* Scripts to facilitate building the program
## Getting Started
First fetch the npm dependencies, including `@solana/web3.js`, by running:
```sh
$ npm install
```
### Select a Network
The client connects to a local Solana cluster by default.
To enable on-chain program logs, set the `RUST_LOG` environment variable:
```bash
$ export RUST_LOG=solana_runtime::native_loader=trace,solana_runtime::system_instruction_processor=trace,solana_runtime::bank=debug,solana_bpf_loader=debug,solana_rbpf=debug
```
To start a local Solana cluster run:
```bash
$ npm run localnet:update
$ npm run localnet:up
```
Solana cluster logs are available with:
```bash
$ npm run localnet:logs
```
For more details on working with a local cluster, see the [full instructions](https://github.com/solana-labs/solana-web3.js#local-network).
### Run the test client
```sh
$ npm run start
```
## Pointing to a public Solana cluster
Solana maintains three public clusters:
- `devnet` - Development cluster with airdrops enabled
- `testnet` - Tour De Sol test cluster without airdrops enabled
- `mainnet-beta` - Main cluster
Use npm scripts to configure which cluster.
To point to `devnet`:
```bash
$ npm run cluster:devnet
```
To point back to the local cluster:
```bash
$ npm run cluster:localnet
```

View File

@ -5,7 +5,7 @@ import {Connection, BpfLoader, PublicKey} from '@solana/web3.js';
import semver from 'semver';
import {Token, TokenAmount} from '../client/token';
import {url} from '../../url';
import {url} from '../url';
import {newAccountWithLamports} from '../client/util/new-account-with-lamports';
import {sleep} from '../client/util/sleep';
@ -57,7 +57,7 @@ async function getConnection(): Promise<Connection> {
export async function loadTokenProgram(): Promise<void> {
const NUM_RETRIES = 500; /* allow some number of retries */
const data = await fs.readFile(
'src/program/target/bpfel-unknown-unknown/release/spl_token.so',
'../target/bpfel-unknown-unknown/release/spl_token.so',
);
const connection = await getConnection();
const {feeCalculator} = await connection.getRecentBlockhash();

View File

@ -8,16 +8,16 @@
},
"testnetDefaultChannel": "v1.2.0",
"scripts": {
"start": "babel-node src/cli/main.js",
"start": "babel-node cli/main.js",
"lint": "npm run pretty && eslint .",
"lint:fix": "npm run lint -- --fix",
"flow": "flow",
"flow:watch": "watch 'flow' . --wait=1 --ignoreDirectoryPattern=/doc/",
"lint:watch": "watch 'npm run lint:fix' . --wait=1",
"bpf-sdk:update": "solana-bpf-sdk-install node_modules/@solana/web3.js && npm run clean:program",
"build:program": "./src/program/do.sh build",
"clean:program": "./src/program/do.sh clean",
"test:program": "./src/program/do.sh test",
"bpf-sdk:update": "solana-bpf-sdk-install ../../bin && npm run clean:program",
"build:program": "../../do.sh build token",
"clean:program": "../../do.sh clean token",
"test:program": "../../do.sh test token",
"bench:program": "npm run build:program",
"cluster:localnet": "rm -f .env",
"cluster:devnet": "cp cluster-devnet.env .env",
@ -28,7 +28,7 @@
"localnet:down": "solana-localnet down",
"localnet:logs": "solana-localnet logs -f",
"pretty": "prettier --write '{,src/**/}*.js'",
"postinstall": "npm run bpf-sdk:update && cargo update --manifest-path=src/program/Cargo.toml",
"postinstall": "npm run bpf-sdk:update && cd .. && cargo update --manifest-path=Cargo.toml",
"test": "npm run build:program && npm run flow"
},
"keywords": [],

View File

@ -1 +0,0 @@
/target/

View File

@ -1,24 +0,0 @@
### Building
This project cannot be built directly via cargo and instead requires the build scripts located in Solana's BPF-SDK.
To build via NPM, from the repo's root directory:
`$ npm run build:program`
You can also refer to the `build:program` script in `package.json` as an example of how to call the build scripts directly
### Testing
Unit tests contained within this project can be built via:
`$ ./do.sh test`
For additional system tests refer to [program-test](`../program-test`). System tests are separated into a different project due to conflicts with dependency features
### Clippy
Clippy is also supported via:
`$ ./do.sh clippy`