-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathrun.sh
executable file
·173 lines (142 loc) · 6.5 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh
build() {
find programs | entr -sc 'anchor build'
}
test() {
find programs tests sdk | entr -sc 'anchor build && (cd sdk && yarn build) && RUST_LOG= anchor test --skip-build'
}
test_logs() {
find programs tests sdk | entr -sc 'anchor build && (cd sdk && yarn build) && anchor test --skip-build'
}
build_vault() {
find programs | entr -sc 'anchor build -p conditional_vault'
}
build_launchpad() {
find programs | entr -sc 'anchor build -p launchpad'
}
test_vault() {
# anchor doesn't let you past test files, so we do this weird thing where we
# modify the Anchor.toml and then put it back
#sed -i '2s/\(\(\S\+\s\+\)\{9\}\)\S\+/\1tests\/conditionalVault.ts"/' Anchor.toml
#sleep 10 && sed -i '2s/\(\(\S\+\s\+\)\{9\}\)\S\+/\1tests\/*.ts"/' Anchor.toml &
# find programs tests sdk | entr -sc \
# "anchor build -p conditional_vault && (cd sdk && yarn build) && sed -i '2s/\(\(\S\+\s\+\)\{10\}\)\S\+/\1tests\/conditionalVault\/*.ts\"/' Anchor.toml && (sleep 3 && sed -i '2s/\(\(\S\+\s\+\)\{10\}\)\S\+/\1tests\/\**\/*.ts\"/' Anchor.toml) & RUST_LOG= anchor test --skip-build"
find programs tests sdk | entr -sc 'anchor build -p conditional_vault && (cd sdk && yarn build) && RUST_LOG= anchor test --skip-build'
}
test_no_build() {
find programs tests sdk | entr -sc '(cd sdk && yarn build) && RUST_LOG= anchor test --skip-build'
}
test_logs_no_build() {
find programs tests sdk | entr -sc '(cd sdk && yarn build) && anchor test --skip-build'
}
# ./test.sh build_verifiable autocrat
build_verifiable() {
PROGRAM_NAME=$1
solana-verify build --library-name "$PROGRAM_NAME" -b ellipsislabs/solana:1.16.10
}
deploy() {
PROGRAM_NAME=$1
CLUSTER=$2
solana program deploy --use-rpc -u "$CLUSTER" --program-id ./target/deploy/"$PROGRAM_NAME"-keypair.json ./target/deploy/"$PROGRAM_NAME".so --with-compute-unit-price 5 --max-sign-attempts 15 && PROGRAM_ID=$(solana-keygen pubkey ./target/deploy/"$PROGRAM_NAME"-keypair.json) && anchor idl init --filepath ./target/idl/"$PROGRAM_NAME".json $PROGRAM_ID --provider.cluster "$CLUSTER"
}
deploy_verifiable() {
PROGRAM_NAME=$1
CLUSTER=$2
solana program deploy --use-rpc -u "$CLUSTER" --program-id ./target/deploy/"$PROGRAM_NAME"-keypair.json ./verifiable-builds/"$PROGRAM_NAME".so --with-compute-unit-price 5 --max-sign-attempts 15 && PROGRAM_ID=$(solana-keygen pubkey ./target/deploy/"$PROGRAM_NAME"-keypair.json) && anchor idl init --filepath ./target/idl/"$PROGRAM_NAME".json $PROGRAM_ID --provider.cluster "$CLUSTER"
}
write_buffer_verifiable() {
PROGRAM_NAME=$1
CLUSTER=$2
solana program write-buffer --use-rpc -u "$CLUSTER" ./verifiable-builds/"$PROGRAM_NAME".so --with-compute-unit-price 5 --max-sign-attempts 15
}
export_verifiable() {
PROGRAM_NAME=$1
PROGRAM_ID=$2
FEATURES=$3
solana-verify export-pda-tx https://github.com/metaDAOproject/futarchy --program-id "$PROGRAM_ID" --uploader 6awyHMshBGVjJ3ozdSJdyyDE1CTAXUwrpNMaRGMsb4sf -b ellipsislabs/solana:1.17.16 --library-name "$PROGRAM_NAME" -- --features $FEATURES
}
verify() {
PROGRAM_ID=$1
solana-verify remote submit-job --program-id "$PROGRAM_ID" --uploader 6awyHMshBGVjJ3ozdSJdyyDE1CTAXUwrpNMaRGMsb4sf
}
upgrade() {
PROGRAM_NAME=$1
PROGRAM_ID=$2
CLUSTER=$3
anchor upgrade ./target/deploy/"$PROGRAM_NAME".so -p "$PROGRAM_ID" --provider.cluster "$CLUSTER"
}
upgrade_idl() {
PROGRAM_NAME=$1
PROGRAM_ID=$2
CLUSTER=$3
anchor idl upgrade --filepath ./target/idl/"$PROGRAM_NAME".json "$PROGRAM_ID" --provider.cluster "$CLUSTER"
}
# this is for if our program isn't big enough, must be in solana 1.18.x
show_size_diff() {
PROGRAM_NAME=$1
PROGRAM_ID=$2
CLUSTER=$3
IS_VERIFIABLE=$4
EXISTING_SIZE=$(solana program show "$PROGRAM_ID" -u "$CLUSTER" | awk '/Data Length:/ {print $3}')
if [ "$IS_VERIFIABLE" = "true" ]; then
NEW_SIZE=$(wc -c < ./verifiable-builds/"$PROGRAM_NAME".so)
else
NEW_SIZE=$(wc -c < ./target/deploy/"$PROGRAM_NAME".so)
fi
echo "Existing size: $EXISTING_SIZE bytes"
echo "New size: $NEW_SIZE bytes"
DIFF=$((NEW_SIZE - EXISTING_SIZE))
echo "Size difference: $DIFF bytes"
if [ "$NEW_SIZE" -gt "$EXISTING_SIZE" ]; then
echo "New program is larger than existing one. You may need to run: solana program extend $PROGRAM_ID $DIFF -u \"$CLUSTER\""
fi
}
bankrun() {
(find programs && find tests) | entr -csr 'anchor build -p autocrat && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/autocrat.ts'
}
test_amm() {
find programs tests | entr -csr 'anchor build -p amm && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/amm.ts'
}
test_amm_logs() {
find programs tests | entr -csr 'anchor build -p amm && yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/amm.ts'
}
bankrun_migrator() {
(find programs && find tests) | entr -csr 'anchor build -p autocrat_migrator && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/migrator.ts'
}
bankrun_timelock() {
find programs tests sdk | entr -cs '(cd sdk && yarn build) && anchor build -p optimistic_timelock && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/timelock.ts'
}
bankrun_vault_logs() {
find programs tests sdk | entr -cs '(cd sdk && yarn build) && anchor build -p optimistic_timelock && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/timelock.ts'
}
bankrun_logs() {
(find programs && find tests) | entr -csr 'anchor build -p autocrat && yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/autocrat.ts'
}
case "$1" in
build) build ;;
build_launchpad) build_launchpad ;;
test) test ;;
test_logs) test_logs ;;
test_logs_no_build) test_logs_no_build ;;
vault) test_vault ;;
build_vault) build_vault ;;
test_no_build) test_no_build ;;
build_verifiable) build_verifiable "$2" ;;
deploy) deploy "$2" "$3" ;;
deploy_verifiable) deploy_verifiable "$2" "$3" ;;
write_buffer_verifiable) write_buffer_verifiable "$2" "$3" ;;
export_verifiable) export_verifiable "$2" "$3" "$4" ;;
verify) verify "$2" ;;
upgrade) upgrade "$2" "$3" "$4" ;;
upgrade_idl) upgrade_idl "$2" "$3" "$4" ;;
bankrun) bankrun ;;
test_amm) test_amm ;;
test_amm_logs) test_amm_logs ;;
bankrun_vault) bankrun_vault ;;
bankrun_migrator) bankrun_migrator ;;
bankrun_timelock) bankrun_timelock ;;
bankrun_vault_logs) bankrun_vault_logs ;;
bankrun_logs) bankrun_logs ;;
show_size_diff) show_size_diff "$2" "$3" "$4" "$5" ;;
*) echo "Unknown command: $1" ;;
esac