Skip to content

Commit 3fada86

Browse files
committed
updating remaining if-fatal blocks to require
1 parent 8f0b2ee commit 3fada86

File tree

1 file changed

+24
-41
lines changed

1 file changed

+24
-41
lines changed

rpc/block_test.go

+24-41
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ func TestBlockNumber(t *testing.T) {
4646
blockNumber, err := testConfig.provider.BlockNumber(context.Background())
4747
require.NoError(t, err, "BlockNumber should not return an error")
4848

49-
if diff, err := spy.Compare(blockNumber, false); err != nil || diff != "FullMatch" {
50-
t.Fatal("expecting to match", err)
51-
}
52-
if blockNumber <= 3000 {
53-
t.Fatal("Block number should be > 3000, instead: ", blockNumber)
54-
}
49+
diff, err := spy.Compare(blockNumber, false)
50+
require.NoError(t, err, "expecting to match")
51+
require.Equal(t, "FullMatch", diff, "expecting to match, instead %s", diff)
52+
53+
require.False(t, blockNumber <= 3000, fmt.Sprintf("Block number should be > 3000, instead: %d", blockNumber))
5554
}
5655
}
5756

@@ -90,15 +89,13 @@ func TestBlockHashAndNumber(t *testing.T) {
9089
blockHashAndNumber, err := testConfig.provider.BlockHashAndNumber(context.Background())
9190
require.NoError(t, err, "BlockHashAndNumber should not return an error")
9291

93-
if diff, err := spy.Compare(blockHashAndNumber, false); err != nil || diff != "FullMatch" {
94-
t.Fatal("expecting to match", err)
95-
}
96-
if blockHashAndNumber.BlockNumber < 3000 {
97-
t.Fatal("Block number should be > 3000, instead: ", blockHashAndNumber.BlockNumber)
98-
}
99-
if !strings.HasPrefix(blockHashAndNumber.BlockHash.String(), "0x") {
100-
t.Fatal("current block hash should return a string starting with 0x")
101-
}
92+
diff, err := spy.Compare(blockHashAndNumber, false)
93+
require.NoError(t, err, "expecting to match")
94+
require.Equal(t, "FullMatch", diff, "expecting to match, instead %s", diff)
95+
96+
require.False(t, blockHashAndNumber.BlockNumber <= 3000, "Block number should be > 3000, instead: %d", blockHashAndNumber.BlockNumber)
97+
98+
require.True(t, strings.HasPrefix(blockHashAndNumber.BlockHash.String(), "0x"), "current block hash should return a string starting with 0x")
10299
}
103100
}
104101

@@ -238,13 +235,10 @@ func TestBlockWithTxHashes(t *testing.T) {
238235
if test.ExpectedErr != nil {
239236
continue
240237
}
241-
if !strings.HasPrefix(block.BlockHash.String(), "0x") {
242-
t.Fatal("Block Hash should start with \"0x\", instead", block.BlockHash)
243-
}
244238

245-
if len(block.Transactions) == 0 {
246-
t.Fatal("the number of transaction should not be 0")
247-
}
239+
require.True(t, strings.HasPrefix(block.BlockHash.String(), "0x"), "Block Hash should start with \"0x\", instead: %s", block.BlockHash)
240+
require.NotEmpty(t, block.Transactions, "the number of transactions should not be 0")
241+
248242
if test.ExpectedBlockWithTxHashes != nil {
249243
if (*test.ExpectedBlockWithTxHashes).BlockHash == &felt.Zero {
250244
continue
@@ -315,13 +309,8 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) {
315309
_, err = spy.Compare(blockWithTxs, false)
316310
require.NoError(t, err, "expecting to match")
317311

318-
if !strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x") {
319-
t.Fatal("Block Hash should start with \"0x\", instead", blockWithTxs.BlockHash)
320-
}
321-
322-
if len(blockWithTxs.Transactions) == 0 {
323-
t.Fatal("the number of transaction should not be 0")
324-
}
312+
require.True(t, strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x"), "Block Hash should start with \"0x\", instead: %s", blockWithTxs.BlockHash)
313+
require.NotEmpty(t, blockWithTxs.Transactions, "the number of transactions should not be 0")
325314

326315
if test.want != nil {
327316
if (*test.want).BlockHash == &felt.Zero {
@@ -789,26 +778,20 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) {
789778
require.NoError(t, err, "Expected to compare the BlockWithTxs.")
790779

791780
if diff != "FullMatch" {
792-
if _, err := spy.Compare(blockWithTxs, false); err != nil {
793-
t.Fatal(err)
794-
}
795-
}
796-
if !strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x") {
797-
t.Fatal("Block Hash should start with \"0x\", instead", blockWithTxs.BlockHash)
781+
_, err = spy.Compare(blockWithTxs, false)
782+
require.NoError(t, err, "Unable to compare the count.")
798783
}
799784

800-
if len(blockWithTxs.Transactions) == 0 {
801-
t.Fatal("the number of transaction should not be 0")
802-
}
785+
require.True(t, strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x"), "Block Hash should start with \"0x\", instead: %s", blockWithTxs.BlockHash)
786+
require.NotEmpty(t, blockWithTxs.Transactions, "the number of transactions should not be 0")
787+
803788
if test.ExpectedBlockWithTxs != nil {
804789
if test.ExpectedBlockWithTxs.BlockHash == &felt.Zero {
805790
continue
806791
}
807-
if !cmp.Equal(test.ExpectedBlockWithTxs.Transactions[test.LookupTxnPositionInExpected], blockWithTxs.Transactions[test.LookupTxnPositionInOriginal]) {
808-
t.Fatalf("the expected transaction blocks to match, instead: %s", cmp.Diff(test.ExpectedBlockWithTxs.Transactions[test.LookupTxnPositionInExpected], blockWithTxs.Transactions[test.LookupTxnPositionInOriginal]))
809-
}
792+
require.True(t, cmp.Equal(test.ExpectedBlockWithTxs.Transactions[test.LookupTxnPositionInExpected], blockWithTxs.Transactions[test.LookupTxnPositionInOriginal]),
793+
"the expected transaction blocks to match, instead: %s", cmp.Diff(test.ExpectedBlockWithTxs.Transactions[test.LookupTxnPositionInExpected], blockWithTxs.Transactions[test.LookupTxnPositionInOriginal]))
810794
}
811-
812795
}
813796
}
814797

0 commit comments

Comments
 (0)