Skip to content

Commit 886a14e

Browse files
authored
[dev] Improve setup script (#77)
1 parent 8c1f63a commit 886a14e

File tree

5 files changed

+19
-47
lines changed

5 files changed

+19
-47
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ First, install both the [Solana CLI tools](https://docs.solana.com/cli/install-s
2121

2222
Install [Docker](https://docs.docker.com/engine/install/).
2323

24+
Install jq and gsed.
25+
26+
```bash
27+
brew install gnu-sed
28+
brew install jq
29+
```
30+
2431
### Web Frontend
2532

2633
The frontend depends on a postgres database for storing claims and on an instance of Solana to send on-chain transactions.

frontend/integration/integrationTest.test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ describe('integration test', () => {
116116
let mint: Token
117117
let treasury: PublicKey
118118
beforeAll(async () => {
119-
await airdrop(
120-
tokenDispenserProvider.connection,
121-
LAMPORTS_PER_SOL,
122-
tokenDispenserProvider.claimant
123-
)
124-
const walletBalance = await tokenDispenserProvider.connection.getBalance(
125-
wallet.publicKey
126-
)
127-
expect(walletBalance).toEqual(LAMPORTS_PER_SOL)
128-
129119
const mintAndTreasury =
130120
await tokenDispenserProvider.setupMintAndTreasury()
131121
mint = mintAndTreasury.mint

frontend/scripts/setup.sh

+10-31
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ TOKEN_DISPENSER_DIR="$DIR/../../token-dispenser";
1414
TOKEN_DISPENSER_PID=Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS
1515
TOKEN_DISPENSER_SO="$TOKEN_DISPENSER_DIR/target/deploy/token_dispenser.so"
1616

17-
VALIDATOR_PID=
18-
1917
usage() {
2018
cat <<EOF
2119
Usage: $0 -d[--dev]|-t[--test] -v[--verbose] --no-postgres -h[--help]
@@ -109,38 +107,21 @@ function populate() {
109107
npm run populate;
110108
}
111109

110+
function build_program() {
111+
cd "$TOKEN_DISPENSER_DIR";
112+
anchor run export;
113+
}
114+
112115
function run_integration_tests() {
113116
cd "$DIR";
114117
npm run test;
115118
}
116119

117-
118-
function start_test_validator() {
119-
cd "$TOKEN_DISPENSER_DIR";
120-
anchor run export;
121-
solana-test-validator -r \
122-
--bpf-program "$TOKEN_DISPENSER_PID" "$TOKEN_DISPENSER_SO" \
123-
--quiet \
124-
&
125-
VALIDATOR_PID=$!
126-
sleep 5
127-
}
128-
129120
function start_anchor_localnet() {
130121
cd "$TOKEN_DISPENSER_DIR";
131-
anchor run export;
132122
anchor localnet;
133123
}
134124

135-
136-
function stop_test_validator() {
137-
set +e
138-
[ -z $VALIDATOR_PID ] || (
139-
kill $VALIDATOR_PID
140-
)
141-
return 0
142-
}
143-
144125
function stop_anchor_localnet() {
145126
solana_pid=$(pgrep -f '[s]olana-test-validator' || true)
146127
if [ -n "$solana_pid" ]; then
@@ -162,23 +143,23 @@ function cleanup() {
162143
echo "shutting down solana-test-validator if running"
163144
fi
164145
stop_anchor_localnet;
165-
stop_test_validator;
166-
167146
}
168147

169148
function main() {
170149
# run clean up in case of failures from previous run
171150
cleanup;
172151
# setup postgres docker
173152
setup_postgres_docker;
153+
# start solana-test-validator
154+
build_program;
155+
start_anchor_localnet &
156+
sleep 5
174157
if [ "$dev" -eq 1 ]; then
175158
if [ "$verbose" -eq 1 ]; then
176159
echo "dev mode"
177-
echo "populate db and deploy solana-test-validator using anchor localnet"
160+
echo "populate db and deploy and initialize program"
178161
fi
179162
printf "\n\n**Running solana-test-validator until CTRL+C detected**\n\n"
180-
start_anchor_localnet &
181-
sleep 5
182163
populate;
183164
# wait for ctrl-c
184165
( trap exit SIGINT ; read -r -d '' _ </dev/tty )
@@ -187,8 +168,6 @@ function main() {
187168
echo "test mode"
188169
echo "running frontend tests"
189170
fi
190-
start_test_validator
191-
sleep 5
192171
run_integration_tests;
193172
else
194173
echo "no mode selected"

token-dispenser/Anchor.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ url = "https://api.apr.dev"
99

1010
[provider]
1111
cluster = "Localnet"
12-
wallet = "~/.config/solana/id.json"
12+
wallet = "../frontend/integration/keys/solana_private_key.json"
1313

1414
[scripts]
1515
test = "cargo test-bpf"

token-dispenser/scripts/export_idl.sh

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ generate_declaration_file() {
2424

2525
prog="$(basename $PROGRAM_SO .json)"
2626
OUT_PATH="$OUT_DIR/$prog.ts"
27-
if [ ! $(which gsed) ]; then
28-
PREFIX=$(echo $prog | sed -E 's/(^|_)([a-z])/\U\2/g')
29-
else
30-
PREFIX=$(echo $prog | gsed -E 's/(^|_)([a-z])/\U\2/g')
31-
fi
27+
PREFIX=$(echo $prog | gsed -E 's/(^|_)([a-z])/\U\2/g')
3228
typename="${PREFIX}"
3329

3430
# types

0 commit comments

Comments
 (0)