2020-07-08 18:11:02 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
)
|
|
|
|
|
2021-01-06 20:56:40 +00:00
|
|
|
func (suite *GenesisTestSuite) TestTransactionLogsValidate() {
|
2020-07-08 18:11:02 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
txLogs TransactionLogs
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"valid log",
|
|
|
|
TransactionLogs{
|
2021-01-06 20:56:40 +00:00
|
|
|
Hash: suite.hash.String(),
|
2020-07-08 18:11:02 +00:00
|
|
|
Logs: []*ethtypes.Log{
|
|
|
|
{
|
2021-01-06 20:56:40 +00:00
|
|
|
Address: suite.address,
|
2020-07-08 18:11:02 +00:00
|
|
|
Topics: []ethcmn.Hash{ethcmn.BytesToHash([]byte("topic"))},
|
|
|
|
Data: []byte("data"),
|
|
|
|
BlockNumber: 1,
|
2021-01-06 20:56:40 +00:00
|
|
|
TxHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
TxIndex: 1,
|
2021-01-06 20:56:40 +00:00
|
|
|
BlockHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
Index: 1,
|
|
|
|
Removed: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"empty hash",
|
|
|
|
TransactionLogs{
|
2021-01-06 20:56:40 +00:00
|
|
|
Hash: ethcmn.Hash{}.String(),
|
2020-07-08 18:11:02 +00:00
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid log",
|
|
|
|
TransactionLogs{
|
2021-01-06 20:56:40 +00:00
|
|
|
Hash: suite.hash.String(),
|
2020-07-08 18:11:02 +00:00
|
|
|
Logs: []*ethtypes.Log{nil},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"hash mismatch log",
|
|
|
|
TransactionLogs{
|
2021-01-06 20:56:40 +00:00
|
|
|
Hash: suite.hash.String(),
|
2020-07-08 18:11:02 +00:00
|
|
|
Logs: []*ethtypes.Log{
|
|
|
|
{
|
2021-01-06 20:56:40 +00:00
|
|
|
Address: suite.address,
|
2020-07-08 18:11:02 +00:00
|
|
|
Topics: []ethcmn.Hash{ethcmn.BytesToHash([]byte("topic"))},
|
|
|
|
Data: []byte("data"),
|
|
|
|
BlockNumber: 1,
|
|
|
|
TxHash: ethcmn.BytesToHash([]byte("other_hash")),
|
|
|
|
TxIndex: 1,
|
2021-01-06 20:56:40 +00:00
|
|
|
BlockHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
Index: 1,
|
|
|
|
Removed: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
err := tc.txLogs.Validate()
|
|
|
|
if tc.expPass {
|
2021-01-06 20:56:40 +00:00
|
|
|
suite.Require().NoError(err, tc.name)
|
2020-07-08 18:11:02 +00:00
|
|
|
} else {
|
2021-01-06 20:56:40 +00:00
|
|
|
suite.Require().Error(err, tc.name)
|
2020-07-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 20:56:40 +00:00
|
|
|
func (suite *GenesisTestSuite) TestValidateLog() {
|
2020-07-08 18:11:02 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
log *ethtypes.Log
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"valid log",
|
|
|
|
ðtypes.Log{
|
2021-01-06 20:56:40 +00:00
|
|
|
Address: suite.address,
|
2020-07-08 18:11:02 +00:00
|
|
|
Topics: []ethcmn.Hash{ethcmn.BytesToHash([]byte("topic"))},
|
|
|
|
Data: []byte("data"),
|
|
|
|
BlockNumber: 1,
|
2021-01-06 20:56:40 +00:00
|
|
|
TxHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
TxIndex: 1,
|
2021-01-06 20:56:40 +00:00
|
|
|
BlockHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
Index: 1,
|
|
|
|
Removed: false,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"nil log", nil, false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"zero address",
|
|
|
|
ðtypes.Log{
|
|
|
|
Address: ethcmn.Address{},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"empty block hash",
|
|
|
|
ðtypes.Log{
|
2021-01-06 20:56:40 +00:00
|
|
|
Address: suite.address,
|
2020-07-08 18:11:02 +00:00
|
|
|
BlockHash: ethcmn.Hash{},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"zero block number",
|
|
|
|
ðtypes.Log{
|
2021-01-06 20:56:40 +00:00
|
|
|
Address: suite.address,
|
|
|
|
BlockHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
BlockNumber: 0,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"empty tx hash",
|
|
|
|
ðtypes.Log{
|
2021-01-06 20:56:40 +00:00
|
|
|
Address: suite.address,
|
|
|
|
BlockHash: suite.hash,
|
2020-07-08 18:11:02 +00:00
|
|
|
BlockNumber: 1,
|
|
|
|
TxHash: ethcmn.Hash{},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
err := ValidateLog(tc.log)
|
|
|
|
if tc.expPass {
|
2021-01-06 20:56:40 +00:00
|
|
|
suite.Require().NoError(err, tc.name)
|
2020-07-08 18:11:02 +00:00
|
|
|
} else {
|
2021-01-06 20:56:40 +00:00
|
|
|
suite.Require().Error(err, tc.name)
|
2020-07-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|