Skip to content

Commit

Permalink
chore: clean up sync_test tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed May 4, 2023
1 parent 4d31ad4 commit 87ae5d0
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 177 deletions.
32 changes: 19 additions & 13 deletions nodebuilder/tests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ Note: 15 is not available because DASer will be stopped before reaching this hei
Another note: this test disables share exchange to speed up test results.
*/
func TestFraudProofBroadcasting(t *testing.T) {
const (
blocks = 15
bsize = 2
btime = time.Millisecond * 300
)
sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime))
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)

fillDn := swamp.FillBlocks(ctx, sw.ClientContext, sw.Accounts, bsize, blocks)
const (
blocks = 15
blockSize = 2
blockTime = time.Millisecond * 300
)

sw := swamp.NewSwamp(t, swamp.WithBlockTime(blockTime))
fillDn := swamp.FillBlocks(ctx, sw.ClientContext, sw.Accounts, blockSize, blocks)

cfg := nodebuilder.DefaultConfig(node.Bridge)
cfg.Share.UseShareExchange = false
bridge := sw.NewNodeWithConfig(
Expand All @@ -53,12 +55,13 @@ func TestFraudProofBroadcasting(t *testing.T) {

err := bridge.Start(ctx)
require.NoError(t, err)
addrs, err := peer.AddrInfoToP2pAddrs(host.InfoFromHost(bridge.Host))
require.NoError(t, err)

cfg = nodebuilder.DefaultConfig(node.Full)
cfg.Share.UseShareExchange = false
addrs, err := peer.AddrInfoToP2pAddrs(host.InfoFromHost(bridge.Host))
require.NoError(t, err)
cfg.Header.TrustedPeers = append(cfg.Header.TrustedPeers, addrs[0].String())

store := nodebuilder.MockStore(t, cfg)
full := sw.NewNodeWithStore(node.Full, store)

Expand All @@ -70,14 +73,17 @@ func TestFraudProofBroadcasting(t *testing.T) {
subscr, err := full.FraudServ.Subscribe(ctx, byzantine.BadEncoding)
require.NoError(t, err)

p := <-subscr
require.Equal(t, 10, int(p.Height()))

select {
case p := <-subscr:
require.Equal(t, 10, int(p.Height()))
case <-ctx.Done():
t.Fatal("fraud proof was not received in time")
}
// This is an obscure way to check if the Syncer was stopped.
// If we cannot get a height header within a timeframe it means the syncer was stopped
// FIXME: Eventually, this should be a check on service registry managing and keeping
// lifecycles of each Module.
syncCtx, syncCancel := context.WithTimeout(context.Background(), btime)
syncCtx, syncCancel := context.WithTimeout(context.Background(), blockTime)
_, err = full.HeaderServ.GetByHeight(syncCtx, 100)
require.ErrorIs(t, err, context.DeadlineExceeded)
syncCancel()
Expand Down
Loading

0 comments on commit 87ae5d0

Please sign in to comment.