Commit f3be6521 authored by Hamdi Allam's avatar Hamdi Allam

address some ci issues

parent a217c500
package api package api
import ( import (
"math/big"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
...@@ -25,7 +26,7 @@ func (mbv *MockBridgeView) DepositsByAddress(address common.Address) ([]*databas ...@@ -25,7 +26,7 @@ func (mbv *MockBridgeView) DepositsByAddress(address common.Address) ([]*databas
{ {
Deposit: database.Deposit{ Deposit: database.Deposit{
GUID: uuid.MustParse(guid1), GUID: uuid.MustParse(guid1),
InitiatedL1EventGUID: guid2, InitiatedL1EventGUID: uuid.MustParse(guid2),
Tx: database.Transaction{}, Tx: database.Transaction{},
TokenPair: database.TokenPair{}, TokenPair: database.TokenPair{},
}, },
...@@ -34,13 +35,28 @@ func (mbv *MockBridgeView) DepositsByAddress(address common.Address) ([]*databas ...@@ -34,13 +35,28 @@ func (mbv *MockBridgeView) DepositsByAddress(address common.Address) ([]*databas
}, nil }, nil
} }
// DepositsByAddress mocks returning deposits by an address
func (mbv *MockBridgeView) DepositByMessageNonce(nonce *big.Int) (*database.Deposit, error) {
return &database.Deposit{
GUID: uuid.MustParse(guid1),
InitiatedL1EventGUID: uuid.MustParse(guid2),
Tx: database.Transaction{},
TokenPair: database.TokenPair{},
}, nil
}
// LatestDepositMessageNonce mocks returning the latest cross domain message nonce for a deposit
func (mbv *MockBridgeView) LatestDepositMessageNonce() (*big.Int, error) {
return big.NewInt(0), nil
}
// WithdrawalsByAddress mocks returning withdrawals by an address // WithdrawalsByAddress mocks returning withdrawals by an address
func (mbv *MockBridgeView) WithdrawalsByAddress(address common.Address) ([]*database.WithdrawalWithTransactionHashes, error) { func (mbv *MockBridgeView) WithdrawalsByAddress(address common.Address) ([]*database.WithdrawalWithTransactionHashes, error) {
return []*database.WithdrawalWithTransactionHashes{ return []*database.WithdrawalWithTransactionHashes{
{ {
Withdrawal: database.Withdrawal{ Withdrawal: database.Withdrawal{
GUID: uuid.MustParse(guid2), GUID: uuid.MustParse(guid2),
InitiatedL2EventGUID: guid1, InitiatedL2EventGUID: uuid.MustParse(guid1),
WithdrawalHash: common.HexToHash("0x456"), WithdrawalHash: common.HexToHash("0x456"),
Tx: database.Transaction{}, Tx: database.Transaction{},
TokenPair: database.TokenPair{}, TokenPair: database.TokenPair{},
...@@ -50,6 +66,33 @@ func (mbv *MockBridgeView) WithdrawalsByAddress(address common.Address) ([]*data ...@@ -50,6 +66,33 @@ func (mbv *MockBridgeView) WithdrawalsByAddress(address common.Address) ([]*data
}, nil }, nil
} }
// WithdrawalsByMessageNonce mocks returning withdrawals by a withdrawal hash
func (mbv *MockBridgeView) WithdrawalByMessageNonce(nonce *big.Int) (*database.Withdrawal, error) {
return &database.Withdrawal{
GUID: uuid.MustParse(guid2),
InitiatedL2EventGUID: uuid.MustParse(guid1),
WithdrawalHash: common.HexToHash("0x456"),
Tx: database.Transaction{},
TokenPair: database.TokenPair{},
}, nil
}
// WithdrawalsByHash mocks returning withdrawals by a withdrawal hash
func (mbv *MockBridgeView) WithdrawalByHash(address common.Hash) (*database.Withdrawal, error) {
return &database.Withdrawal{
GUID: uuid.MustParse(guid2),
InitiatedL2EventGUID: uuid.MustParse(guid1),
WithdrawalHash: common.HexToHash("0x456"),
Tx: database.Transaction{},
TokenPair: database.TokenPair{},
}, nil
}
// LatestWithdrawalMessageNonce mocks returning the latest cross domain message nonce for a withdrawal
func (mbv *MockBridgeView) LatestWithdrawalMessageNonce() (*big.Int, error) {
return big.NewInt(0), nil
}
func TestHealthz(t *testing.T) { func TestHealthz(t *testing.T) {
api := NewApi(&MockBridgeView{}) api := NewApi(&MockBridgeView{})
request, err := http.NewRequest("GET", "/healthz", nil) request, err := http.NewRequest("GET", "/healthz", nil)
......
...@@ -38,7 +38,7 @@ type Deposit struct { ...@@ -38,7 +38,7 @@ type Deposit struct {
// the message nonce serves as a unique identifier for this // the message nonce serves as a unique identifier for this
// deposit. Once this generalizes to more than 1 deployed // deposit. Once this generalizes to more than 1 deployed
// bridge, we need to include the `CrossDomainMessenger` address // bridge, we need to include the `CrossDomainMessenger` address
// such that the (messenger_addr, nonce) is the unique identifer // such that the (messenger_addr, nonce) is the unique identifier
// for a bridge msg // for a bridge msg
SentMessageNonce U256 SentMessageNonce U256
...@@ -61,7 +61,7 @@ type Withdrawal struct { ...@@ -61,7 +61,7 @@ type Withdrawal struct {
// the message nonce serves as a unique identifier for this // the message nonce serves as a unique identifier for this
// withdrawal. Once this generalizes to more than 1 deployed // withdrawal. Once this generalizes to more than 1 deployed
// bridge, we need to include the `CrossDomainMessenger` address // bridge, we need to include the `CrossDomainMessenger` address
// such that the (messenger_addr, nonce) is the unique identifer // such that the (messenger_addr, nonce) is the unique identifier
// for a bridge msg // for a bridge msg
SentMessageNonce U256 SentMessageNonce U256
...@@ -209,7 +209,7 @@ func (db *bridgeDB) MarkFinalizedWithdrawalEvent(guid, finalizedL1EventGuid uuid ...@@ -209,7 +209,7 @@ func (db *bridgeDB) MarkFinalizedWithdrawalEvent(guid, finalizedL1EventGuid uuid
} }
if withdrawal.ProvenL1EventGUID == nil { if withdrawal.ProvenL1EventGUID == nil {
return errors.New(fmt.Sprintf("withdrawal %s marked finalized prior to being proven", guid)) return fmt.Errorf("withdrawal %s marked finalized prior to being proven", guid)
} }
withdrawal.FinalizedL1EventGUID = &finalizedL1EventGuid withdrawal.FinalizedL1EventGUID = &finalizedL1EventGuid
......
...@@ -45,48 +45,10 @@ func (p *ProcessedContractEvents) AddLog(log *types.Log, time uint64) *database. ...@@ -45,48 +45,10 @@ func (p *ProcessedContractEvents) AddLog(log *types.Log, time uint64) *database.
return &contractEvent return &contractEvent
} }
func DecodeFromProcessedContractEvents[ABI any](p *ProcessedContractEvents, name string, contractAbi *abi.ABI) ([]*ABI, error) {
eventAbi, ok := contractAbi.Events[name]
if !ok {
return nil, errors.New(fmt.Sprintf("event %s not present in supplied ABI", name))
}
decodedEvents := []*ABI{}
for _, event := range p.eventsBySignature[eventAbi.ID] {
log := p.eventLog[event.GUID]
var decodedEvent ABI
err := contractAbi.UnpackIntoInterface(&decodedEvent, name, log.Data)
if err != nil {
return nil, err
}
// handle topics if present
if len(log.Topics) > 1 {
var indexedArgs abi.Arguments
for _, arg := range eventAbi.Inputs {
if arg.Indexed {
indexedArgs = append(indexedArgs, arg)
}
}
// The first topic (event signature) is ommitted
err := abi.ParseTopics(&decodedEvent, indexedArgs, log.Topics[1:])
if err != nil {
return nil, err
}
}
decodedEvents = append(decodedEvents, &decodedEvent)
}
return decodedEvents, nil
}
func UnpackLog(out interface{}, log *types.Log, name string, contractAbi *abi.ABI) error { func UnpackLog(out interface{}, log *types.Log, name string, contractAbi *abi.ABI) error {
eventAbi, ok := contractAbi.Events[name] eventAbi, ok := contractAbi.Events[name]
if !ok { if !ok {
return errors.New(fmt.Sprintf("event %s not present in supplied ABI", name)) return fmt.Errorf("event %s not present in supplied ABI", name)
} else if len(log.Topics) == 0 { } else if len(log.Topics) == 0 {
return errors.New("anonymous events are not supported") return errors.New("anonymous events are not supported")
} else if log.Topics[0] != eventAbi.ID { } else if log.Topics[0] != eventAbi.ID {
...@@ -107,7 +69,7 @@ func UnpackLog(out interface{}, log *types.Log, name string, contractAbi *abi.AB ...@@ -107,7 +69,7 @@ func UnpackLog(out interface{}, log *types.Log, name string, contractAbi *abi.AB
} }
} }
// The first topic (event signature) is ommitted // The first topic (event signature) is omitted
err := abi.ParseTopics(out, indexedArgs, log.Topics[1:]) err := abi.ParseTopics(out, indexedArgs, log.Topics[1:])
if err != nil { if err != nil {
return err return err
......
...@@ -18,7 +18,7 @@ var ( ...@@ -18,7 +18,7 @@ var (
) )
type StandardBridgeInitiatedEvent struct { type StandardBridgeInitiatedEvent struct {
// We hardcode to ERC20 since ETH can be psuedo-represented as an ERC20 utilizing // We hardcode to ERC20 since ETH can be pseudo-represented as an ERC20 utilizing
// the hardcoded ETH address // the hardcoded ETH address
*bindings.L1StandardBridgeERC20BridgeInitiated *bindings.L1StandardBridgeERC20BridgeInitiated
...@@ -27,7 +27,7 @@ type StandardBridgeInitiatedEvent struct { ...@@ -27,7 +27,7 @@ type StandardBridgeInitiatedEvent struct {
} }
type StandardBridgeFinalizedEvent struct { type StandardBridgeFinalizedEvent struct {
// We hardcode to ERC20 since ETH can be psuedo-represented as an ERC20 utilizing // We hardcode to ERC20 since ETH can be pseudo-represented as an ERC20 utilizing
// the hardcoded ETH address // the hardcoded ETH address
*bindings.L1StandardBridgeERC20BridgeFinalized *bindings.L1StandardBridgeERC20BridgeFinalized
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment