2023-01-14 10:12:34 +01:00
|
|
|
package filter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-01-14 10:20:16 +01:00
|
|
|
"github.com/grassrootseconomics/cic-chain-events/pkg/fetch"
|
2023-01-14 10:12:34 +01:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/zerodha/logf"
|
|
|
|
)
|
|
|
|
|
2023-02-24 11:28:30 +01:00
|
|
|
type TransferFilterSuite struct {
|
2023-01-14 10:12:34 +01:00
|
|
|
suite.Suite
|
|
|
|
filter Filter
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:28:30 +01:00
|
|
|
func (s *TransferFilterSuite) SetupSuite() {
|
2023-01-14 10:12:34 +01:00
|
|
|
logg := logf.New(
|
|
|
|
logf.Opts{
|
|
|
|
Level: logf.DebugLevel,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-02-24 11:28:30 +01:00
|
|
|
s.filter = NewTransferFilter(TransferFilterOpts{
|
2023-01-14 10:12:34 +01:00
|
|
|
Logg: logg,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:28:30 +01:00
|
|
|
func (s *TransferFilterSuite) TestTranfserInputs() {
|
2023-01-14 10:12:34 +01:00
|
|
|
type testCase struct {
|
|
|
|
transactionData fetch.Transaction
|
|
|
|
want bool
|
|
|
|
wantErr bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generated with eth-encode
|
|
|
|
tests := []testCase{
|
|
|
|
{
|
|
|
|
transactionData: fetch.Transaction{
|
|
|
|
InputData: "0xa9059cbb000000000000000000000000000000000000000000000000000000000000dEaD00000000000000000000000000000000000000000000000000000000000003e8",
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
transactionData: fetch.Transaction{
|
|
|
|
InputData: "0x23b872dd000000000000000000000000000000000000000000000000000000000000dEaD000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000003e8",
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
transactionData: fetch.Transaction{
|
|
|
|
InputData: "0x449a52f8000000000000000000000000000000000000000000000000000000000000dEaD00000000000000000000000000000000000000000000000000000000000003e8",
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
transactionData: fetch.Transaction{
|
|
|
|
InputData: "0x8d72ec9d000000000000000000000000000000000000000000000000000000000000dEaD00000000000000000000000000000000000000000000000000000000000003e8",
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2023-03-11 10:29:51 +01:00
|
|
|
next, err := s.filter.Execute(context.Background(), &test.transactionData)
|
2023-01-14 10:12:34 +01:00
|
|
|
s.NoError(err)
|
|
|
|
s.Equal(test.want, next)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:28:30 +01:00
|
|
|
func TestTransferFilterSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(TransferFilterSuite))
|
2023-01-14 10:12:34 +01:00
|
|
|
}
|