| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/ipfs/go-test/random" |
| 7 | "github.com/ipfs/kubo/config" |
| 8 | "github.com/ipfs/kubo/test/cli/harness" |
| 9 | "github.com/stretchr/testify/assert" |
| 10 | ) |
| 11 | |
| 12 | func TestDHTOptimisticProvide(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | |
| 15 | t.Run("optimistic provide smoke test", func(t *testing.T) { |
| 16 | nodes := harness.NewT(t).NewNodes(2).Init() |
| 17 | |
| 18 | nodes[0].UpdateConfig(func(cfg *config.Config) { |
| 19 | cfg.Experimental.OptimisticProvide = true |
| 20 | // Optimistic provide only works with the legacy provider. |
| 21 | cfg.Provide.DHT.SweepEnabled = config.False |
| 22 | }) |
| 23 | |
| 24 | nodes.StartDaemons().Connect() |
| 25 | defer nodes.StopDaemons() |
| 26 | |
| 27 | hash := nodes[0].IPFSAddStr(string(random.Bytes(100))) |
| 28 | nodes[0].IPFS("routing", "provide", hash) |
| 29 | |
| 30 | res := nodes[1].IPFS("routing", "findprovs", "--num-providers=1", hash) |
| 31 | assert.Equal(t, nodes[0].PeerID().String(), res.Stdout.Trimmed()) |
| 32 | }) |
| 33 | } |