aboutsummaryrefslogtreecommitdiff
path: root/fstest/testserver/init.d/TestSia
blob: 9b11cafa2e7b3338b27532290e0986e4b0f09e6a (plain)
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
#!/usr/bin/env bash

set -e

NAME=Sia

# shellcheck disable=SC1090
. "$(dirname "$0")"/docker.bash

# wait until Sia test network is up,
# the Sia renter forms contracts on the blockchain
# and the renter is upload ready
wait_for_sia() {
    until curl -A Sia-Agent -s "$1" | grep -q '"ready":true'
    do
        sleep 5
    done
}
export -f wait_for_sia

start() {
    # use non-production sia port in test
    SIA_CONN="127.0.0.1:39980"
    # nebulouslabs/siaantfarm is stale, use up-to-date image
    ANTFARM_IMAGE=ivandeex/sia-antfarm:latest

    # pull latest antfarm image (dont use local image)
    docker pull --quiet $ANTFARM_IMAGE

    # start latest antfarm with default config
    docker run --rm --detach --name "$NAME" \
            --publish "${SIA_CONN}:9980" \
            $ANTFARM_IMAGE

    # wait until the test network is upload ready
    timeout 300 bash -c "wait_for_sia ${SIA_CONN}/renter/uploadready"

    # confirm backend type in the generated rclone.conf
    echo "type=sia"
    # override keys in the Sia section of generated rclone.conf
    echo "api_url=http://${SIA_CONN}/"
    # hint test harness where to probe for connection
    echo "_connect=${SIA_CONN}"
}

stop() {
    if status ; then
        docker logs "$NAME" >> sia-test.log 2>&1
        docker kill "$NAME"
        echo "${NAME} stopped"
    fi
}

# shellcheck disable=SC1090
. "$(dirname "$0")"/run.bash