You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

71 lines
3.1 KiB

#!/usr/bin/env bash
# No real need to use stderr here since it's just tests.
set -eE
shellcheck "$0"
# Before we build...
go fmt
go doc
go test
go fmt ./cmd/settlersd/
go test ./cmd/settlersd/ -v
go doc ./cmd/settlersd/
go fmt ./cmd/settlers/
go test ./cmd/settlers/ -v
go doc ./cmd/settlers/
go build
go build ./cmd/settlersd/
go build ./cmd/settlers/
strip -s settlersd
strip -s settlers
./settlersd sample_configuration/valid.json &
PID=$!
cleanup() {
echo "Cleaning up."
kill "$PID"
echo "Cleaning up."
}
trap cleanup $(seq 1 64) ERR
fail() {
echo "FAIL: $1"
cleanup
exit 1
}
curl -s --show-error --fail "http://localhost:2828/SettlersAlive" || fail "Should 200"
# Should 404
curl -s --show-error --fail "http://localhost:2828/404" && fail "Should 404"
# Should fail because bad token
curl -s --show-error --fail "http://localhost:2828/balance/badtoken" && fail "Should be bad token"
# Should fail because bad token
curl -s --show-error --fail "http://localhost:2828/balance/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b" && fail "Should be not enabled"
./settlers enable http://localhost:2828 deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 || fail "Cannot enable"
./settlers enable http://localhost:2828 deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 && fail "Should not be able to enable twice."
./settlers balance http://localhost:2828 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 || fail "Cannot get balance"
./settlers add http://localhost:2828 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 100 || fail "Cannot add"
./settlers subtract http://localhost:2828 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 40 || fail "Cannot subtract"
./settlers balance http://localhost:2828 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 || fail "Cannot get balance"
./settlers subtract http://localhost:2828 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 61 && fail "Can subtract too much."
./settlers depositonlytokenenabled http://localhost:2828 "$(./settlers deposittoken 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b)" 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 || fail "deposit only token not enabled"
./settlers deposit http://localhost:2828 "$(./settlers deposittoken 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b)" 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 100 || fail "Cannot deposit"
cleanup
sleep 0.1
echo Success.