Skip to content

Commit

Permalink
fix: Compiler's Error models changed slightly - ensuring that they al…
Browse files Browse the repository at this point in the history
…l return the underlying Reason
  • Loading branch information
randomshinichi committed Sep 17, 2019
1 parent 152bac5 commit caf7069
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions integration_test/compiler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integrationtest

import (
"reflect"
"testing"

"github.com/aeternity/aepp-sdk-go/v5/aeternity"
Expand All @@ -27,6 +28,23 @@ func TestCompiler(t *testing.T) {
}
golden.Assert(t, compiled, simplestorageBytecode)
})
t.Run("CompileErrorDeserialization", func(t *testing.T) {
// Compiler v4.0.0-rc4 and onwards will return a
// CompileContractForbidden type for compile errors. If the error type
// changes in the future and cannot be deserialized, reflect.TypeOf(err)
// will be of type json.UnmarshalError instead, and this test will fail.
wontcompileSource := `contract Test =
entrypoint some_test(ae_address: address) =
// let test = String.concat("\x19Ethereum Signed Message:\n52", Address.to_str(ae_address))
ae_addres
`

_, err := c.CompileContract(wontcompileSource, aeternity.Config.Compiler.Backend)
errtype := reflect.TypeOf(err).String()
if errtype != "*operations.CompileContractForbidden" {
t.Error(err)
}
})
t.Run("DecodeCallResult", func(t *testing.T) {
// taken from contract_test.go
_, err := c.DecodeCallResult("ok", "cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACr8s/aY", "main", string(golden.Get(t, identitySource)), aeternity.Config.Compiler.Backend)
Expand Down
6 changes: 6 additions & 0 deletions swagguard/compiler/models/compiler_error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions swagguard/compiler/models/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions swagguard/compiler/models/error_pos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions swagguard/compiler_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@ func TestCompilerErrorModelDereferencing(t *testing.T) {
t.Errorf("Expected to find %s when printing out the models.Error: got %s instead", reason, printedError)
}
}

func TestCompilerCompilationErrorsModelDereferencing(t *testing.T) {
err1 := &models.CompilerError{}
err1.UnmarshalBinary([]byte(`{"message":"Unbound variable ae_addres at line 4, column 9","pos":{"col":9,"line":4},"type":"type_error"}`))
err2 := &models.CompilerError{}
err2.UnmarshalBinary([]byte(`{"message":"Also I don't like your face","pos":{"col":0,"line":0},"type":"wrong_programmer_error"}`))

compileContractForbidden := operations.CompileContractForbidden{
Payload: []*models.CompilerError{err1, err2},
}
printedError := fmt.Sprintf("%s", compileContractForbidden)
lookForError1 := "Unbound variable ae_addres"
lookForError2 := "Also I don't like your face"

if !(strings.Contains(printedError, lookForError1) && strings.Contains(printedError, lookForError2)) {
t.Errorf("Expected []*models.CompilerError to include the messages %s and %s; got %s instead", lookForError1, lookForError2, printedError)
}
}

0 comments on commit caf7069

Please sign in to comment.