Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

impr(events): Naming clarity and I don't trust the sussiness from before #15

Merged
merged 11 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ linters:
- lll # reports long lines
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
Expand Down Expand Up @@ -253,7 +254,6 @@ linters:
#- grouper # analyzes expression groups
#- importas # enforces consistent import aliases
#- maintidx # measures the maintainability index of each function
#- misspell # [useless] finds commonly misspelled English words in comments
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
#- tagliatelle # checks the struct tags
Expand Down
2 changes: 1 addition & 1 deletion core/vm/precompile/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (pe *PrecompileEvent) MakeTopics(event *sdk.Event) ([]common.Hash, error) {
// `MakeData` returns the Ethereum log `Data` field for a valid cosmos event. `Data` is a slice of
// bytes which store an Ethereum event's non-indexed arguments, packed into bytes. This function
// packs the values of the incoming Cosmos event's attributes, which correspond to the
// Ethereum event's non-indexed arguements, into bytes and returns a byte slice.
// Ethereum event's non-indexed arguments, into bytes and returns a byte slice.
func (pe *PrecompileEvent) MakeData(event *sdk.Event) ([]byte, error) {
attrVals := make([]any, len(pe.nonIndexedInputs))

Expand Down
20 changes: 10 additions & 10 deletions types/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
)

// `maxTopicsLen` is the maximum number of topics hashes allowed in an Eth log.
const maxTopicsLen = 4
// `maxIndexedArgs` is the maximum number of indexed arguments allowed in an Ethereum event log.
const maxIndexedArgs = 3

type (
Argument = abi.Argument
Expand Down Expand Up @@ -52,15 +52,15 @@ func ToMixedCase(input string) string {
// indexed arguments are provided by the inputs ABI.
func GetIndexed(args abi.Arguments) abi.Arguments {
var indexed abi.Arguments
numIndexed := 0
for i := range args {
if args[i].Indexed {
numIndexed++
if numIndexed == maxTopicsLen {
panic("number of indexed arguments is more than allowed by Eth event log")
}
indexed = append(indexed, args[i])
for _, arg := range args {
if arg.Indexed {
indexed = append(indexed, arg)
}
}

if len(indexed) > maxIndexedArgs {
panic("number of indexed arguments is more than allowed by Eth event log")
}

return indexed
}
39 changes: 21 additions & 18 deletions types/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,27 @@ var _ = Describe("ABI Test Suite", func() {
})

Describe("Test GetIndexed", func() {
var allArgs = abi.Arguments{
abi.Argument{},
abi.Argument{
Name: "1",
Indexed: true,
},
abi.Argument{
Name: "2",
Indexed: true,
},
abi.Argument{},
abi.Argument{},
abi.Argument{},
abi.Argument{
Name: "3",
Indexed: true,
},
}
var allArgs abi.Arguments
BeforeEach(func() {
allArgs = abi.Arguments{
abi.Argument{},
abi.Argument{
Name: "1",
Indexed: true,
},
abi.Argument{
Name: "2",
Indexed: true,
},
abi.Argument{},
abi.Argument{},
abi.Argument{},
abi.Argument{
Name: "3",
Indexed: true,
},
}
})

It("should correctly filter out indexed arguments", func() {
indexedArgs := abi.Arguments{
Expand Down