summary refs log tree commit diff
path: root/nixos/tests/ipfs.nix
blob: 3cff7e99ff88796eb50fe4ad221065c69df89980 (plain) (blame)
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
import ./make-test.nix ({ pkgs, ...} : {
  name = "ipfs";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ mguentner ];
  };

  nodes = {
    adder =
      { ... }:
      {
        services.ipfs = {
          enable = true;
          defaultMode = "norouting";
          gatewayAddress = "/ip4/127.0.0.1/tcp/2323";
          apiAddress = "/ip4/127.0.0.1/tcp/2324";
        };
        networking.firewall.allowedTCPPorts = [ 4001 ];
      };
    getter =
      { ... }:
      {
        services.ipfs = {
          enable = true;
          defaultMode = "norouting";
          autoMount = true;
        };
        networking.firewall.allowedTCPPorts = [ 4001 ];
      };
  };

  testScript = ''
    startAll;
    $adder->waitForUnit("ipfs-norouting");
    $getter->waitForUnit("ipfs-norouting");

    # wait until api is available
    $adder->waitUntilSucceeds("ipfs --api /ip4/127.0.0.1/tcp/2324 id");
    my $addrId = $adder->succeed("ipfs --api /ip4/127.0.0.1/tcp/2324 id -f=\"<id>\"");
    my $addrIp = (split /[ \/]+/, $adder->succeed("ip -o -4 addr show dev eth1"))[3];

    $adder->mustSucceed("[ -n \"\$(ipfs --api /ip4/127.0.0.1/tcp/2324 config Addresses.Gateway | grep /ip4/127.0.0.1/tcp/2323)\" ]");

    # wait until api is available
    $getter->waitUntilSucceeds("ipfs --api /ip4/127.0.0.1/tcp/5001 id");
    my $ipfsHash = $adder->mustSucceed("echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add | cut -d' ' -f2");
    chomp($ipfsHash);

    $adder->mustSucceed("[ -n \"\$(echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add | grep added)\" ]");

    $getter->mustSucceed("ipfs --api /ip4/127.0.0.1/tcp/5001 swarm connect /ip4/$addrIp/tcp/4001/ipfs/$addrId");
    $getter->mustSucceed("[ -n \"\$(ipfs --api /ip4/127.0.0.1/tcp/5001 cat /ipfs/$ipfsHash | grep fnord)\" ]");
    $getter->mustSucceed("[ -n \"$(cat /ipfs/$ipfsHash | grep fnord)\" ]");
    '';
})