Skip to content

Commit

Permalink
hash
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Oct 30, 2023
1 parent 0bc0194 commit 9b159df
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
10 changes: 5 additions & 5 deletions services/sinner/api/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions services/sinner/contracts/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion services/sinner/db/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions services/sinner/db/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ 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)

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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions services/sinner/db/sql/base/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: "",
})

Expand All @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions services/sinner/db/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 9b159df

Please sign in to comment.