Skip to content

Commit

Permalink
Fixed TestBlockWithTxsAndInvokeTXNV1 observations
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed May 13, 2024
1 parent aac45b3 commit b6b1c26
Showing 1 changed file with 13 additions and 50 deletions.
63 changes: 13 additions & 50 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,6 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) {
// Returns:
//
// none
//
// TODO: Find a block with such a Txn
func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) {
testConfig := beforeEach(t)

Expand Down Expand Up @@ -758,17 +756,6 @@ func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) {
testSet := map[string][]testSetType{
"mock": {},
"testnet": {
{
BlockID: WithBlockTag("latest"),
ExpectedError: nil,
},
{
BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x6df565874b2ea6a02d346a23f9efb0b26abbf5708b51bb12587f88a49052964")),
ExpectedError: nil,
want: &fullBlockSepolia64159,
LookupTxnPositionInExpected: 0,
LookupTxnPositionInOriginal: 4,
},
{
BlockID: WithBlockNumber(64159),
ExpectedError: nil,
Expand All @@ -780,51 +767,27 @@ func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) {
"mainnet": {},
}[testEnv]

require := require.New(t)
for _, test := range testSet {
spy := NewSpy(testConfig.provider.c)
testConfig.provider.c = spy
blockWithTxsInterface, err := testConfig.provider.BlockWithTxs(context.Background(), test.BlockID)
if err != test.ExpectedError {
t.Fatal("BlockWithTxHashes match the expected error:", err)
}
if test.ExpectedError != nil && blockWithTxsInterface == nil {
continue
}
blockWithTxs, ok := blockWithTxsInterface.(*Block)
if !ok {
t.Fatalf("expecting *rpv02.Block, instead %T", blockWithTxsInterface)
}
_, err = spy.Compare(blockWithTxs, false)
if err != nil {
t.Fatal("expecting to match", err)
}
if !strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x") {
t.Fatal("Block Hash should start with \"0x\", instead", blockWithTxs.BlockHash)
}

if len(blockWithTxs.Transactions) == 0 {
t.Fatal("the number of transaction should not be 0")
}
require.NoError(err, "Unable to fetch the given block.")

if test.want != nil {
if (*test.want).BlockHash == &felt.Zero {
continue
}
blockWithTxs, ok := blockWithTxsInterface.(*Block)
require.True(ok, "Failed to assert the Interface as *Block.")
require.Equal(blockWithTxs.BlockHash.String()[:2], "0x", "Block Hash should start with \"0x\".")
require.NotEqual(len(blockWithTxs.Transactions), 0, "The number of transaction should not be 0.")

invokeV1Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV1)
if !ok {
t.Fatal("expected invoke v1 transaction")
}
invokeV1Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV1)
if !ok {
t.Fatal("expected invoke v1 transaction")
}
require.Equal(t, invokeV1Want.TransactionHash.String(), invokeV1Block.TransactionHash.String(), "expected equal TransactionHash")
require.Equal(t, invokeV1Want.InvokeTxnV1.MaxFee.String(), invokeV1Block.InvokeTxnV1.MaxFee.String(), "expected equal maxfee")
require.Equal(t, invokeV1Want.InvokeTxnV1.Calldata[1].String(), invokeV1Block.InvokeTxnV1.Calldata[1].String(), "expected equal calldatas")
invokeV1Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV1)
require.True(ok, "Expected invoke v1 transaction.")

}
invokeV1Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV1)
require.True(ok, "Expected invoke v1 transaction.")

require.Equal(invokeV1Want.TransactionHash.String(), invokeV1Block.TransactionHash.String(), "Expected equal TransactionHash.")
require.Equal(invokeV1Want.InvokeTxnV1.MaxFee.String(), invokeV1Block.InvokeTxnV1.MaxFee.String(), "Expected equal maxfee.")
require.Equal(invokeV1Want.InvokeTxnV1.Calldata[1].String(), invokeV1Block.InvokeTxnV1.Calldata[1].String(), "Expected equal calldatas.")
}
}

Expand Down

0 comments on commit b6b1c26

Please sign in to comment.