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

Commit

Permalink
fix(precompile): better error msgs (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
shampoobera authored Jul 27, 2023
1 parent 79324a1 commit c5069d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ out

# integration testing coverage
coverage-testunitcover.txt
coverage-teste2ecover.txt
1 change: 1 addition & 0 deletions e2e/localnet/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4U
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.50.0-beta.0.0.20230727121850-bd61e84ef162 h1:jYNPV5xfv3bsH+B6y1qxo2ru2cKz+1vJQqSa7L86byQ=
github.com/cosmos/cosmos-sdk v0.50.0-beta.0.0.20230727121850-bd61e84ef162/go.mod h1:MF/wnXyreoL0g8YdRZhUD4apPdgebMc29LgMJB+dh6M=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
Expand Down
13 changes: 11 additions & 2 deletions eth/core/precompile/method_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ func validateOutputs(implMethod reflect.Method, abiMethod *abi.Method) error {

// Last parameter of Go precompile implementation is an error (for reverts), so we skip that.
if implMethodNumOut-1 != len(abiMethod.Outputs) {
return errors.New("number of return types mismatch")
return fmt.Errorf(
"number of return args mismatch: %v expects %v return vals, %v returns %v vals",
abiMethod.Name,
len(abiMethod.Outputs),
implMethod.Name, implMethodNumOut-1,
)
}

// Validate that our implementation returns an error (revert) as the last param.
Expand All @@ -154,7 +159,11 @@ func validateOutputs(implMethod reflect.Method, abiMethod *abi.Method) error {
reflect.New(implMethodReturnType).Elem(), reflect.New(abiMethodReturnType).Elem(),
); err != nil {
return fmt.Errorf(
"return type mismatch: %v != %v", implMethodReturnType, abiMethodReturnType,
"return type mismatch: %v expects %v, %v has %v",
abiMethod.Name,
abiMethodReturnType,
implMethod.Name,
implMethodReturnType,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions eth/core/precompile/method_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ var _ = Describe("Method", func() {
numReturnMismatch, found := reflect.TypeOf(m).MethodByName("NumReturnMismatch")
Expect(found).To(BeTrue())
Expect(validateOutputs(numReturnMismatch, &exampleFunc).Error()).To(Equal(
"number of return types mismatch"))
"number of return args mismatch: exampleFunc expects 1 return vals, NumReturnMismatch returns 0 vals"))

returnTypeMismatch, found := reflect.TypeOf(m).MethodByName("ReturnTypeMismatch")
Expect(found).To(BeTrue())
Expect(validateOutputs(returnTypeMismatch, &exampleFunc).Error()).To(Equal(
"return type mismatch: string != bool"))
"return type mismatch: exampleFunc expects bool, ReturnTypeMismatch has string"))
})
})

Expand Down

0 comments on commit c5069d5

Please sign in to comment.