1
2import ./make-test.nix ({ pkgs, ...} : {
3 name = "ipfs";
4 meta = with pkgs.stdenv.lib.maintainers; {
5 maintainers = [ mguentner ];
6 };
7
8 nodes = {
9 adder =
10 { ... }:
11 {
12 services.ipfs = {
13 enable = true;
14 defaultMode = "norouting";
15 gatewayAddress = "/ip4/127.0.0.1/tcp/2323";
16 apiAddress = "/ip4/127.0.0.1/tcp/2324";
17 };
18 networking.firewall.allowedTCPPorts = [ 4001 ];
19 };
20 getter =
21 { ... }:
22 {
23 services.ipfs = {
24 enable = true;
25 defaultMode = "norouting";
26 autoMount = true;
27 };
28 networking.firewall.allowedTCPPorts = [ 4001 ];
29 };
30 };
31
32 testScript = ''
33 startAll;
34 $adder->waitForUnit("ipfs-norouting");
35 $getter->waitForUnit("ipfs-norouting");
36
37 # wait until api is available
38 $adder->waitUntilSucceeds("ipfs --api /ip4/127.0.0.1/tcp/2324 id");
39 my $addrId = $adder->succeed("ipfs --api /ip4/127.0.0.1/tcp/2324 id -f=\"<id>\"");
40 my $addrIp = (split /[ \/]+/, $adder->succeed("ip -o -4 addr show dev eth1"))[3];
41
42 $adder->mustSucceed("[ -n \"\$(ipfs --api /ip4/127.0.0.1/tcp/2324 config Addresses.Gateway | grep /ip4/127.0.0.1/tcp/2323)\" ]");
43
44 # wait until api is available
45 $getter->waitUntilSucceeds("ipfs --api /ip4/127.0.0.1/tcp/5001 id");
46 my $ipfsHash = $adder->mustSucceed("echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add | cut -d' ' -f2");
47 chomp($ipfsHash);
48
49 $adder->mustSucceed("[ -n \"\$(echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add | grep added)\" ]");
50
51 $getter->mustSucceed("ipfs --api /ip4/127.0.0.1/tcp/5001 swarm connect /ip4/$addrIp/tcp/4001/ipfs/$addrId");
52 $getter->mustSucceed("[ -n \"\$(ipfs --api /ip4/127.0.0.1/tcp/5001 cat /ipfs/$ipfsHash | grep fnord)\" ]");
53 $getter->mustSucceed("[ -n \"$(cat /ipfs/$ipfsHash | grep fnord)\" ]");
54 '';
55})