Skip to content

Commit

Permalink
Merge pull request #1045 from onflow/supun/dynamic-type-conformance
Browse files Browse the repository at this point in the history
Add more tests for imported array/dictionary value type conformance
  • Loading branch information
SupunS authored Jul 5, 2021
2 parents 3cfe0f1 + 1503e7e commit 8ec25b6
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion runtime/convertValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,27 @@ func TestMalformedArgumentPassing(t *testing.T) {
},
}

// Struct with nested array with mismatching element type
malformedStruct5 := cadence.Struct{
StructType: &cadence.StructType{
Location: utils.TestLocation,
QualifiedIdentifier: "Bar",
Fields: []cadence.Field{
{
Identifier: "a",
Type: cadence.VariableSizedArrayType{
ElementType: malformedStructType1,
},
},
},
},
Fields: []cadence.Value{
cadence.NewArray([]cadence.Value{
cadence.NewString("mismatching value"),
}),
},
}

type argumentPassingTest struct {
label string
typeSignature string
Expand Down Expand Up @@ -1665,14 +1686,30 @@ func TestMalformedArgumentPassing(t *testing.T) {
}),
expectedErrType: &InvalidValueTypeError{},
},
{
label: "Nested array with mismatching element",
typeSignature: "[[String]]",
exportedValue: cadence.NewArray([]cadence.Value{
cadence.NewArray([]cadence.Value{
cadence.NewInt(5),
}),
}),
expectedErrType: &InvalidValueTypeError{},
},
{
label: "Inner array with mismatching element",
typeSignature: "Bar",
exportedValue: malformedStruct5,
expectedErrType: &MalformedValueError{},
},
{
label: "Malformed Optional",
typeSignature: "Foo?",
exportedValue: cadence.NewOptional(malformedStruct1),
expectedErrType: &MalformedValueError{},
},
{
label: "Malformed Map",
label: "Malformed dictionary",
typeSignature: "{String: Foo}",
exportedValue: cadence.NewDictionary([]cadence.KeyValuePair{
{
Expand All @@ -1682,6 +1719,22 @@ func TestMalformedArgumentPassing(t *testing.T) {
}),
expectedErrType: &MalformedValueError{},
},
{
label: "Nested dictionary with mismatching element",
typeSignature: "{String: {String: String}}",
exportedValue: cadence.NewDictionary([]cadence.KeyValuePair{
{
Key: cadence.NewString("hello"),
Value: cadence.NewDictionary([]cadence.KeyValuePair{
{
Key: cadence.NewString("hello"),
Value: cadence.NewInt(6),
},
}),
},
}),
expectedErrType: &InvalidValueTypeError{},
},
}

testArgumentPassing := func(test argumentPassingTest) {
Expand Down

0 comments on commit 8ec25b6

Please sign in to comment.