From 9b159df240c39f588420dc059520fad6e83e97f4 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Mon, 30 Oct 2023 14:16:28 +0000 Subject: [PATCH] hash --- services/sinner/api/resolver_test.go | 10 +++++----- services/sinner/contracts/suite_test.go | 4 ++-- services/sinner/db/event.go | 2 +- services/sinner/db/read_test.go | 10 +++++----- services/sinner/db/sql/base/write.go | 10 +++++----- services/sinner/db/write_test.go | 13 +++++++------ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/services/sinner/api/resolver_test.go b/services/sinner/api/resolver_test.go index 95a6f2f59a..875a422b60 100644 --- a/services/sinner/api/resolver_test.go +++ b/services/sinner/api/resolver_test.go @@ -68,14 +68,14 @@ func (t *APISuite) TestGetExecuted() { } func (t *APISuite) TestMessageStatus() { - txHash := common.BigToHash(big.NewInt(gofakeit.Int64())).String() - desTxHash := common.BigToHash(big.NewInt(gofakeit.Int64())).String() - messageHash := common.BigToHash(big.NewInt(gofakeit.Int64())).String() + txHash := common.BigToHash(big.NewInt(gofakeit.Int64())) + desTxHash := common.BigToHash(big.NewInt(gofakeit.Int64())) + messageHash := common.BigToHash(big.NewInt(gofakeit.Int64())) err := t.db.StoreOrUpdateMessageStatus(t.GetTestContext(), txHash, messageHash, types.Origin) Nil(t.T(), err) - result, err := t.sinnerAPI.GetMessageStatus(t.GetTestContext(), messageHash) + result, err := t.sinnerAPI.GetMessageStatus(t.GetTestContext(), messageHash.String()) Nil(t.T(), err) NotNil(t.T(), result) Equal(t.T(), txHash, *result.Response.OriginTxHash) @@ -85,7 +85,7 @@ func (t *APISuite) TestMessageStatus() { err = t.db.StoreOrUpdateMessageStatus(t.GetTestContext(), desTxHash, messageHash, types.Destination) Nil(t.T(), err) - desResult, err := t.sinnerAPI.GetMessageStatus(t.GetTestContext(), messageHash) + desResult, err := t.sinnerAPI.GetMessageStatus(t.GetTestContext(), messageHash.String()) Nil(t.T(), err) NotNil(t.T(), desResult) Equal(t.T(), desTxHash, *desResult.Response.DestinationTxHash) diff --git a/services/sinner/contracts/suite_test.go b/services/sinner/contracts/suite_test.go index a18c516c3f..35c4aa2dd4 100644 --- a/services/sinner/contracts/suite_test.go +++ b/services/sinner/contracts/suite_test.go @@ -80,7 +80,7 @@ func (t *ContractsSuite) SetupSuite() { Data: []byte{}, TxHash: common.BigToHash(big.NewInt(gofakeit.Int64())), TxIndex: uint(gofakeit.Int8()), - BlockHash: common.HexToHash(big.NewInt(gofakeit.Int64()).String()), + BlockHash: mocls.NewMockHash(t.T()), Index: uint(gofakeit.Int8()), Removed: false, } @@ -91,7 +91,7 @@ func (t *ContractsSuite) SetupSuite() { Data: []byte{}, TxHash: common.BigToHash(big.NewInt(gofakeit.Int64())), TxIndex: uint(gofakeit.Int8()), - BlockHash: common.HexToHash(big.NewInt(gofakeit.Int64()).String()), + BlockHash: mocls.NewMockHash(t.T()), Index: uint(gofakeit.Int8()), Removed: false, } diff --git a/services/sinner/db/event.go b/services/sinner/db/event.go index 813ed8414d..e0ba8dab5c 100644 --- a/services/sinner/db/event.go +++ b/services/sinner/db/event.go @@ -20,7 +20,7 @@ type EventDBWriter interface { // StoreLastIndexed stores the last indexed for a contract address StoreLastIndexed(ctx context.Context, contractAddress common.Address, chainID uint32, blockNumber uint64) error // StoreOrUpdateMessageStatus stores/updates the status of a message. - StoreOrUpdateMessageStatus(ctx context.Context, txHash string, messageID string, messageType types.MessageType) error + StoreOrUpdateMessageStatus(ctx context.Context, txHash, messageID common.Hash, messageType types.MessageType) error // UNSAFE_DB gets the underlying gorm db. This is not intended for use in production. // //nolint:golint diff --git a/services/sinner/db/read_test.go b/services/sinner/db/read_test.go index cc4c2b1551..16412faa83 100644 --- a/services/sinner/db/read_test.go +++ b/services/sinner/db/read_test.go @@ -41,9 +41,9 @@ func (t *DBSuite) TestRetrieveLastStoredBlock() { func (t *DBSuite) TestRetrieveMessageStatus() { t.RunOnAllDBs(func(testDB db.EventDB) { - messageHash1 := common.BigToHash(big.NewInt(gofakeit.Int64())).String() - originTxHash1 := common.BigToHash(big.NewInt(gofakeit.Int64())).String() - destinationTxHash1 := common.BigToHash(big.NewInt(gofakeit.Int64())).String() + messageHash1 := common.BigToHash(big.NewInt(gofakeit.Int64())) + originTxHash1 := common.BigToHash(big.NewInt(gofakeit.Int64())) + destinationTxHash1 := common.BigToHash(big.NewInt(gofakeit.Int64())) // Insert origin only record err := testDB.StoreOrUpdateMessageStatus(t.GetTestContext(), originTxHash1, messageHash1, types.Origin) @@ -51,7 +51,7 @@ func (t *DBSuite) TestRetrieveMessageStatus() { Nil(t.T(), err) // Test: Retrieve and validate the origin only record - retrievedStatus1, err := testDB.RetrieveMessageStatus(t.GetTestContext(), messageHash1) + retrievedStatus1, err := testDB.RetrieveMessageStatus(t.GetTestContext(), messageHash1.String()) Nil(t.T(), err) Equal(t.T(), originTxHash1, *retrievedStatus1.OriginTxHash) Equal(t.T(), graphqlModel.MessageStateLastSeenOrigin, *retrievedStatus1.LastSeen) @@ -62,7 +62,7 @@ func (t *DBSuite) TestRetrieveMessageStatus() { Nil(t.T(), err) // Test: Retrieve and validate the updated record - retrievedStatus2, err := testDB.RetrieveMessageStatus(t.GetTestContext(), messageHash1) + retrievedStatus2, err := testDB.RetrieveMessageStatus(t.GetTestContext(), messageHash1.String()) Nil(t.T(), err) Equal(t.T(), originTxHash1, *retrievedStatus2.OriginTxHash) Equal(t.T(), destinationTxHash1, *retrievedStatus2.DestinationTxHash) diff --git a/services/sinner/db/sql/base/write.go b/services/sinner/db/sql/base/write.go index f81c99c736..2e00f43c1b 100644 --- a/services/sinner/db/sql/base/write.go +++ b/services/sinner/db/sql/base/write.go @@ -112,7 +112,7 @@ func (s Store) StoreLastIndexed(parentCtx context.Context, contractAddress commo } // StoreOrUpdateMessageStatus stores or updates the message status. -func (s Store) StoreOrUpdateMessageStatus(ctx context.Context, txHash string, messageHash string, messageType types.MessageType) error { +func (s Store) StoreOrUpdateMessageStatus(ctx context.Context, txHash, messageHash common.Hash, messageType types.MessageType) error { dbTx := s.DB().WithContext(ctx) switch messageType { @@ -122,8 +122,8 @@ func (s Store) StoreOrUpdateMessageStatus(ctx context.Context, txHash string, me Columns: []clause.Column{{Name: "message_hash"}}, DoUpdates: clause.AssignmentColumns([]string{"origin_txhash"}), }).Create(&model.MessageStatus{ - MessageHash: messageHash, - OriginTxHash: txHash, + MessageHash: messageHash.String(), + OriginTxHash: txHash.String(), DestinationTxHash: "", }) @@ -133,9 +133,9 @@ func (s Store) StoreOrUpdateMessageStatus(ctx context.Context, txHash string, me Columns: []clause.Column{{Name: "message_hash"}}, DoUpdates: clause.AssignmentColumns([]string{"destination_txhash"}), }).Create(&model.MessageStatus{ - MessageHash: messageHash, + MessageHash: messageHash.String(), OriginTxHash: "", - DestinationTxHash: txHash, + DestinationTxHash: txHash.String(), }) default: return fmt.Errorf("unknown message type: %s", messageType) diff --git a/services/sinner/db/write_test.go b/services/sinner/db/write_test.go index 004c4a5d10..b86f2d20ef 100644 --- a/services/sinner/db/write_test.go +++ b/services/sinner/db/write_test.go @@ -4,6 +4,7 @@ import ( "github.com/brianvoe/gofakeit/v6" "github.com/ethereum/go-ethereum/common" . "github.com/stretchr/testify/assert" + "github.com/synapsecns/sanguine/ethergo/mocks" "github.com/synapsecns/sanguine/services/sinner/db" "github.com/synapsecns/sanguine/services/sinner/db/model" "github.com/synapsecns/sanguine/services/sinner/types" @@ -167,8 +168,8 @@ func (t *DBSuite) TestStoreLastIndexed() { func (t *DBSuite) TestStoreOrUpdateMessageStatus() { t.RunOnAllDBs(func(testDB db.EventDB) { // Test Case 1: Create message status record with Origin - messageID1 := common.HexToAddress(big.NewInt(gofakeit.Int64()).String()).String() - txHash1 := common.HexToHash(big.NewInt(gofakeit.Int64()).String()).String() + messageID1 := mocks.NewMockHash(t.T()) + txHash1 := mocks.NewMockHash(t.T()) err := testDB.StoreOrUpdateMessageStatus(t.GetTestContext(), txHash1, messageID1, types.Origin) Nil(t.T(), err) @@ -178,8 +179,8 @@ func (t *DBSuite) TestStoreOrUpdateMessageStatus() { Equal(t.T(), txHash1, status1.OriginTxHash) // Test Case 2: Create message status record with Destination - messageID2 := common.HexToAddress(big.NewInt(gofakeit.Int64()).String()).String() - txHash2 := common.HexToHash(big.NewInt(gofakeit.Int64()).String()).String() + messageID2 := common.HexToHash(big.NewInt(gofakeit.Int64()).String()) + txHash2 := mocks.NewMockHash(t.T()) err = testDB.StoreOrUpdateMessageStatus(t.GetTestContext(), txHash2, messageID2, types.Destination) Nil(t.T(), err) @@ -189,7 +190,7 @@ func (t *DBSuite) TestStoreOrUpdateMessageStatus() { Equal(t.T(), txHash2, status2.DestinationTxHash) // Test Case 3: Update message status record with Origin - newTxHash1 := common.HexToHash(big.NewInt(gofakeit.Int64()).String()).String() + newTxHash1 := mocks.NewMockHash(t.T()) err = testDB.StoreOrUpdateMessageStatus(t.GetTestContext(), newTxHash1, messageID1, types.Origin) Nil(t.T(), err) @@ -199,7 +200,7 @@ func (t *DBSuite) TestStoreOrUpdateMessageStatus() { Equal(t.T(), newTxHash1, updatedStatus1.OriginTxHash) // Test Case 4: Update message status record with Destination - newTxHash2 := common.HexToHash(big.NewInt(gofakeit.Int64()).String()).String() + newTxHash2 := mocks.NewMockHash(t.T()) err = testDB.StoreOrUpdateMessageStatus(t.GetTestContext(), newTxHash2, messageID2, types.Destination) Nil(t.T(), err)