Skip to content

Commit

Permalink
Fix failing tests and use typed errors when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
masih committed Jan 22, 2025
1 parent e355c9a commit b2e443d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion chain/lf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (fff *F3) GetLatestCert(ctx context.Context) (*certs.FinalityCertificate, e
func (fff *F3) GetManifest(ctx context.Context) (*manifest.Manifest, error) {
m := fff.inner.Manifest()
if m == nil {
return nil, xerrors.New("no known network manifest")
return nil, manifest.ErrNoManifest
}
if m.InitialPowerTable.Defined() {
return m, nil
Expand Down
26 changes: 15 additions & 11 deletions itests/f3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-f3"
"github.com/filecoin-project/go-f3/certs"
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/manifest"
Expand Down Expand Up @@ -99,10 +100,10 @@ func TestF3_InactiveModes(t *testing.T) {
expectedErrors: map[string]any{
"F3GetOrRenewParticipationTicket": api.ErrF3NotReady,
"F3Participate": api.ErrF3NotReady,
"F3GetCertificate": "F3 is not running",
"F3GetLatestCertificate": "F3 is not running",
"F3GetManifest": "no known network manifest",
"F3GetF3PowerTable": "no known network manifest",
"F3GetCertificate": f3.ErrF3NotRunning.Error(),
"F3GetLatestCertificate": f3.ErrF3NotRunning.Error(),
"F3GetManifest": manifest.ErrNoManifest.Error(),
"F3GetF3PowerTable": manifest.ErrNoManifest.Error(),
},
expectedValues: map[string]any{
"F3GetOrRenewParticipationTicket": (api.F3ParticipationTicket)(nil),
Expand Down Expand Up @@ -343,7 +344,7 @@ func (e *testEnv) waitTillF3Instance(i uint64, timeout time.Duration) {
e.waitFor(func(n *kit.TestFullNode) bool {
c, err := n.F3GetLatestCertificate(e.testCtx)
if err != nil {
require.ErrorContains(e.t, err, "F3 is not running")
require.ErrorContains(e.t, err, f3.ErrF3NotRunning.Error())
return false
}
return c != nil && c.GPBFTInstance >= i
Expand Down Expand Up @@ -441,17 +442,23 @@ func setup(t *testing.T, blocktime time.Duration, opts ...kit.NodeOpt) *testEnv

func newTestManifest(networkName gpbft.NetworkName, bootstrapEpoch int64, blocktime time.Duration) *manifest.Manifest {
return &manifest.Manifest{
Pause: false,
ProtocolVersion: manifest.VersionCapability,
InitialInstance: 0,
BootstrapEpoch: bootstrapEpoch,
NetworkName: networkName,
ExplicitPower: nil,
IgnoreECPower: false,
InitialPowerTable: cid.Undef,
CommitteeLookback: manifest.DefaultCommitteeLookback,
CatchUpAlignment: blocktime / 2,
Gpbft: manifest.GpbftConfig{
// Use smaller time intervals for more responsive test progress/assertion.
Delta: 250 * time.Millisecond,
DeltaBackOffExponent: 1.3,
QualityDeltaMultiplier: 1.0,
MaxLookaheadRounds: 5,
ChainProposedLength: manifest.DefaultGpbftConfig.ChainProposedLength,
RebroadcastBackoffBase: 500 * time.Millisecond,
RebroadcastBackoffSpread: 0.1,
RebroadcastBackoffExponent: 1.3,
Expand All @@ -465,12 +472,9 @@ func newTestManifest(networkName gpbft.NetworkName, bootstrapEpoch int64, blockt
HeadLookback: 0,
Finalize: true,
},
CertificateExchange: manifest.CxConfig{
ClientRequestTimeout: manifest.DefaultCxConfig.ClientRequestTimeout,
ServerRequestTimeout: manifest.DefaultCxConfig.ServerRequestTimeout,
MinimumPollInterval: blocktime,
MaximumPollInterval: 4 * blocktime,
},
CertificateExchange: manifest.DefaultCxConfig,
PubSub: manifest.DefaultPubSubConfig,
ChainExchange: manifest.DefaultChainExchangeConfig,
}
}

Expand Down
5 changes: 3 additions & 2 deletions itests/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-f3"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-state-types/abi"
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
Expand Down Expand Up @@ -569,11 +570,11 @@ func TestGatewayF3(t *testing.T) {
nodes := startNodes(ctx, t)

cert, err := nodes.lite.F3GetLatestCertificate(ctx)
require.ErrorContains(t, err, "F3 is not running")
require.ErrorContains(t, err, f3.ErrF3NotRunning.Error())
require.Nil(t, cert)

cert, err = nodes.lite.F3GetCertificate(ctx, 2)
require.ErrorContains(t, err, "F3 is not running")
require.ErrorContains(t, err, f3.ErrF3NotRunning.Error())
require.Nil(t, cert)
})

Expand Down

0 comments on commit b2e443d

Please sign in to comment.