Skip to content

Commit

Permalink
fix: tests and ui
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Aug 28, 2024
1 parent 8a9d84c commit 2adced1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
18 changes: 9 additions & 9 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func (d *daemon) mustStart() {
}

type providerOutput struct {
ID string
ConnectionError string
Addrs []string
ConnectionMaddrs []string
BitswapCheckOutput BitswapCheckOutput
ID string
ConnectionError string
Addrs []string
ConnectionMaddrs []string
DataAvailableOverBitswap BitswapCheckOutput
}

// runCidCheck looks up the DHT for providers of a given CID and then checks their connectivity and Bitswap availability
Expand Down Expand Up @@ -150,9 +150,9 @@ func (d *daemon) runCidCheck(ctx context.Context, cidStr string) (*[]providerOut
}

provOutput := providerOutput{
ID: provider.ID.String(),
Addrs: addrs,
BitswapCheckOutput: BitswapCheckOutput{},
ID: provider.ID.String(),
Addrs: addrs,
DataAvailableOverBitswap: BitswapCheckOutput{},
}

testHost, err := d.createTestHost()
Expand All @@ -175,7 +175,7 @@ func (d *daemon) runCidCheck(ctx context.Context, cidStr string) (*[]providerOut
} else {
// since we pass a libp2p host that's already connected to the peer the actual connection maddr we pass in doesn't matter
p2pAddr, _ := multiaddr.NewMultiaddr("/p2p/" + provider.ID.String())
provOutput.BitswapCheckOutput = checkBitswapCID(ctx, testHost, cid, p2pAddr)
provOutput.DataAvailableOverBitswap = checkBitswapCID(ctx, testHost, cid, p2pAddr)

for _, c := range testHost.Network().ConnsToPeer(provider.ID) {
provOutput.ConnectionMaddrs = append(provOutput.ConnectionMaddrs, c.RemoteMultiaddr().String())
Expand Down
11 changes: 7 additions & 4 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -177,12 +178,14 @@ func TestBasicIntegration(t *testing.T) {
res.Value(0).Object().Value("ConnectionError").String().IsEmpty()
testHostAddrs := h.Addrs()
for _, addr := range testHostAddrs {
res.Value(0).Object().Value("Addrs").Array().ContainsAny(addr.String())
if manet.IsPublicAddr(addr) {
res.Value(0).Object().Value("Addrs").Array().ContainsAny(addr.String())
}
}

res.Value(0).Object().Value("ConnectionMaddrs").Array()
res.Value(0).Object().Value("BitswapCheckOutput").Object().Value("Error").String().IsEmpty()
res.Value(0).Object().Value("BitswapCheckOutput").Object().Value("Found").Boolean().IsTrue()
res.Value(0).Object().Value("BitswapCheckOutput").Object().Value("Responded").Boolean().IsTrue()
res.Value(0).Object().Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
res.Value(0).Object().Value("DataAvailableOverBitswap").Object().Value("Found").Boolean().IsTrue()
res.Value(0).Object().Value("DataAvailableOverBitswap").Object().Value("Responded").Boolean().IsTrue()
})
}
12 changes: 6 additions & 6 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ <h1 class="dib pa3 ma0 lh-tight">
Run Test
</button>
</div>
<div id="output" style="white-space:pre; overflow-x: scroll;" class="lh-copy fw6"></div>
<div id="output" style="white-space:pre; overflow-x: scroll;" class="lh-copy fw5"></div>
<details class="mt3">
<summary class="f6 fw6">Raw Output</summary>
<pre style="white-space:pre;" class="lh-copy fw6 language-json"><code id="raw-output"></code></pre>
<pre style="white-space:pre;" class="lh-copy fw5 language-json"><code id="raw-output"></code></pre>
</details>
</form>
</section>
Expand Down Expand Up @@ -264,12 +264,12 @@ <h2 class="f4">What does it mean if I get an error?</h2>
function formatJustCidOutput (resp) {
let outText = ""
if (resp.length === 0) {
outText += "❌ No providers found for the given CID\n"
outText += "❌ No providers found for the given CID"
return outText
}

const successfulProviders = resp.reduce((acc, provider) => {
if(provider.ConnectionError === '' && provider.BitswapCheckOutput.Found === true) {
if(provider.ConnectionError === '' && provider.DataAvailableOverBitswap?.Found === true) {
acc++
}
return acc
Expand All @@ -295,12 +295,12 @@ <h2 class="f4">What does it mean if I get an error?</h2>
}
})

outText += `${successfulProviders > 0 ? '✅' : '❌'} Found ${successfulProviders} providers (out of ${resp.length} providers in the DHT) that could be connected to and had the CID available over Bitswap:\n`
outText += `${successfulProviders > 0 ? '✅' : '❌'} Found ${successfulProviders} providers (out of ${resp.length} providers in the DHT) that could be connected to and had the CID available over Bitswap:`
for (const provider of resp) {
const couldConnect = provider.ConnectionError === ''

outText += `\n\t${provider.ID}\n\t\tConnected: ${couldConnect ? "✅" : `❌ ${provider.ConnectionError.replaceAll('\n', '\n\t\t')}` }`
outText += couldConnect ? `\n\t\tBitswap Check: ${provider.BitswapCheckOutput.Found ? `✅` : "❌"} ${provider.BitswapCheckOutput.Error || ''}` : ''
outText += couldConnect ? `\n\t\tBitswap Check: ${provider.DataAvailableOverBitswap.Found ? `✅` : "❌"} ${provider.DataAvailableOverBitswap.Error || ''}` : ''
outText += couldConnect ? provider.ConnectionMaddrs && `\n\t\tSuccessful Connection Multiaddr${provider.ConnectionMaddrs.length > 1 ? 's' : ''}:${provider.ConnectionMaddrs?.join('\n\t\t\t') || ''}` : ''
outText += provider.Addrs.length > 0 ? `\n\t\tPeer Multiaddrs:\n\t\t\t${provider.Addrs.join('\n\t\t\t')}` : ''
}
Expand Down

0 comments on commit 2adced1

Please sign in to comment.