Skip to content

Commit

Permalink
handle partial fill for bebop (#64)
Browse files Browse the repository at this point in the history
* handle partial fill for bebop
  • Loading branch information
ngocthanh1389 authored Aug 14, 2024
1 parent 2a5449b commit 023f5df
Show file tree
Hide file tree
Showing 2 changed files with 273 additions and 77 deletions.
74 changes: 59 additions & 15 deletions pkg/parser/bebop/bebop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestFetchEvent(t *testing.T) {
require.NoError(t, err)
logs, err := client.FilterLogs(context.Background(), ethereum.FilterQuery{
BlockHash: nil,
FromBlock: big.NewInt(20025442),
ToBlock: big.NewInt(20025442),
FromBlock: big.NewInt(19932179),
ToBlock: big.NewInt(19932179),
Addresses: nil,
Topics: [][]common.Hash{
{
Expand All @@ -46,10 +46,10 @@ func TestFetchEvent(t *testing.T) {
t.Log(string(d))
}

func TestParseEvent(t *testing.T) {
func TestParseAggregateOrderEvent(t *testing.T) {
t.Skip("Need to add the rpc url that enables the trace call JSON-RPC")
eventRaw := `[{"address":"0xbbbbbbb520d69a9775e85b458c58c648259fad5f","topics":["0xadd7095becdaa725f0f33243630938c861b0bba83dfd217d4055701aa768ec2e","0x00000000000000000000000000000000b05c492e829fd9c00000000000000000"],"data":"0x","blockNumber":"0x1319062","transactionHash":"0x0f7567ffd5fc92aa552c5e6ebf8173514693aadd5a888c816b4735a931e8c8c3","transactionIndex":"0xe","blockHash":"0x3015d9d1960cab845f333c49f8cb0d81fa89b2c837de8ac22cd645810bb18c83","logIndex":"0x5a","removed":false}]`
events := []types.Log{}
eventRaw := `{"address":"0xbbbbbbb520d69a9775e85b458c58c648259fad5f","topics":["0xadd7095becdaa725f0f33243630938c861b0bba83dfd217d4055701aa768ec2e","0x000000000000000000000000000000006f0760aefdfe33400000000000000000"],"data":"0x","blockNumber":"0x138de04","transactionHash":"0xb9d13c7057d6d0779a14023d8ce469a8266ea89eb2ca4e6f4c085ef0929c6f08","transactionIndex":"0x8","blockHash":"0x54a780bfa027b8cfb16a40bb86be066795e84d6a124582f9a85b8c662f27fda9","logIndex":"0x46","removed":false}`
events := types.Log{}
err := json.Unmarshal([]byte(eventRaw), &events)
require.NoError(t, err)
ethClient, err := ethclient.Dial(rpcURL)
Expand All @@ -58,15 +58,59 @@ func TestParseEvent(t *testing.T) {
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
p := MustNewParser(traceCalls)
for _, event := range events {
log, err := p.Parse(event, uint64(time.Now().Unix()))
require.NoError(t, err)
require.Equal(t, log.EventHash, p.eventHash)
t.Log(log.Maker)
t.Log(log.MakerToken)
t.Log(log.MakerTokenAmount)
t.Log(log.Taker)
t.Log(log.TakerToken)
t.Log(log.TakerTokenAmount)
log, err := p.Parse(events, uint64(time.Now().Unix()))
require.NoError(t, err)
require.Equal(t, log.EventHash, p.eventHash)
t.Log(log.Maker)
t.Log(log.MakerToken)
t.Log(log.MakerTokenAmount)
t.Log(log.Taker)
t.Log(log.TakerToken)
t.Log(log.TakerTokenAmount)
}

func TestParseMultiOrderEvent(t *testing.T) {
t.Skip("Need to add the rpc url that enables the trace call JSON-RPC")
eventRaw := `{"address":"0xbbbbbbb520d69a9775e85b458c58c648259fad5f","topics":["0xadd7095becdaa725f0f33243630938c861b0bba83dfd217d4055701aa768ec2e","0x0000000000000000000000000000000027611cb25303fa700000000000000001"],"data":"0x","blockNumber":"0x133842c","transactionHash":"0xff46ac555ec7da7aa484864dc0df90217b7f46dfa51627c20ef6e25451c64b15","transactionIndex":"0x10","blockHash":"0xb03cd01d48456c60cdf445e35b0a4d7672b80d801245e516336596f0d5b77951","logIndex":"0x85","removed":false}`
events := types.Log{}
err := json.Unmarshal([]byte(eventRaw), &events)
require.NoError(t, err)
ethClient, err := ethclient.Dial(rpcURL)
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(events, uint64(time.Now().Unix()))
require.NoError(t, err)
require.Equal(t, log.EventHash, p.eventHash)
t.Log(log.Maker)
t.Log(log.MakerToken)
t.Log(log.MakerTokenAmount)
t.Log(log.Taker)
t.Log(log.TakerToken)
t.Log(log.TakerTokenAmount)
}

func TestParseSingleOrderEvent(t *testing.T) {
t.Skip("Need to add the rpc url that enables the trace call JSON-RPC")
eventRaw := `{"address":"0xbbbbbbb520d69a9775e85b458c58c648259fad5f","topics":["0xadd7095becdaa725f0f33243630938c861b0bba83dfd217d4055701aa768ec2e","0x0000000000000000000000000000000084e2ab041ba07e400000000000000000"],"data":"0x","blockNumber":"0x1302413","transactionHash":"0xa227c4aed6f3ae86cd8ba02349d0ae5be78337266416ac65cf8a8d095a2f572e","transactionIndex":"0x47","blockHash":"0xbb4a5ae13e2a66f83f444f24078ac3fb6d0b09f610c48d920d3b89d4f20ea86c","logIndex":"0xd8","removed":false}`
events := types.Log{}
err := json.Unmarshal([]byte(eventRaw), &events)
require.NoError(t, err)
ethClient, err := ethclient.Dial(rpcURL)
if err != nil {
panic(err)
}
traceCalls := tracecall.NewCache(rpcnode.NewClient(ethClient))
p := MustNewParser(traceCalls)
log, err := p.Parse(events, uint64(time.Now().Unix()))
require.NoError(t, err)
require.Equal(t, log.EventHash, p.eventHash)
t.Log(log.Maker)
t.Log(log.MakerToken)
t.Log(log.MakerTokenAmount)
t.Log(log.Taker)
t.Log(log.TakerToken)
t.Log(log.TakerTokenAmount)
}
Loading

0 comments on commit 023f5df

Please sign in to comment.