Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 12, 2024
1 parent b314d48 commit 60391e4
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 159 deletions.
66 changes: 38 additions & 28 deletions convert/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,60 @@ import (

"github.com/onflow/flow-go-sdk/test"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow/protobuf/go/flow/entities"
"github.com/stretchr/testify/assert"

"github.com/onflow/flow-emulator/convert"
flowgo "github.com/onflow/flow-go/model/flow"

"github.com/onflow/flow-emulator/convert"
)

func TestVm(t *testing.T) {

t.Parallel()

t.Run("should be able to convert", func(t *testing.T) {
test := func(eventEncodingVersion entities.EventEncodingVersion) {
t.Run(eventEncodingVersion.String(), func(t *testing.T) {
t.Parallel()
t.Run("should be able to convert", func(t *testing.T) {

t.Parallel()

t.Parallel()
idGenerator := test.IdentifierGenerator()

idGenerator := test.IdentifierGenerator()
eventGenerator := test.EventGenerator(eventEncodingVersion)
event1, err := convert.SDKEventToFlow(eventGenerator.New())
assert.NoError(t, err)

eventGenerator := test.EventGenerator()
event1, err := convert.SDKEventToFlow(eventGenerator.New())
assert.NoError(t, err)
event2, err := convert.SDKEventToFlow(eventGenerator.New())
assert.NoError(t, err)

event2, err := convert.SDKEventToFlow(eventGenerator.New())
assert.NoError(t, err)
txnId := flowgo.Identifier(idGenerator.New())
output := fvm.ProcedureOutput{
Logs: []string{"TestLog1", "TestLog2"},
Events: []flowgo.Event{event1, event2},
ComputationUsed: 5,
MemoryEstimate: 1211,
Err: nil,
}

txnId := flowgo.Identifier(idGenerator.New())
output := fvm.ProcedureOutput{
Logs: []string{"TestLog1", "TestLog2"},
Events: []flowgo.Event{event1, event2},
ComputationUsed: 5,
MemoryEstimate: 1211,
Err: nil,
}
tr, err := convert.VMTransactionResultToEmulator(txnId, output)
assert.NoError(t, err)

tr, err := convert.VMTransactionResultToEmulator(txnId, output)
assert.NoError(t, err)
assert.Equal(t, txnId, flowgo.Identifier(tr.TransactionID))
assert.Equal(t, output.Logs, tr.Logs)

assert.Equal(t, txnId, flowgo.Identifier(tr.TransactionID))
assert.Equal(t, output.Logs, tr.Logs)
flowEvents, err := convert.FlowEventsToSDK(output.Events)
assert.NoError(t, err)
assert.Equal(t, flowEvents, tr.Events)

flowEvents, err := convert.FlowEventsToSDK(output.Events)
assert.NoError(t, err)
assert.Equal(t, flowEvents, tr.Events)
assert.Equal(t, output.ComputationUsed, tr.ComputationUsed)
assert.Equal(t, output.MemoryEstimate, tr.MemoryEstimate)
assert.Equal(t, output.Err, tr.Error)
})
})
}

assert.Equal(t, output.ComputationUsed, tr.ComputationUsed)
assert.Equal(t, output.MemoryEstimate, tr.MemoryEstimate)
assert.Equal(t, output.Err, tr.Error)
})
test(entities.EventEncodingVersion_JSON_CDC_V0)
test(entities.EventEncodingVersion_CCF_V0)
}
59 changes: 40 additions & 19 deletions storage/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/onflow/flow-go-sdk/test"
flowgo "github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow/protobuf/go/flow/entities"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -50,16 +51,26 @@ func TestEncodeTransactionResult(t *testing.T) {

t.Parallel()

result := unittest.StorableTransactionResultFixture()
test := func(eventEncodingVersion entities.EventEncodingVersion) {

data, err := encodeTransactionResult(result)
require.Nil(t, err)
t.Run(eventEncodingVersion.String(), func(t *testing.T) {
t.Parallel()

var decodedResult types.StorableTransactionResult
err = decodeTransactionResult(&decodedResult, data)
require.Nil(t, err)
result := unittest.StorableTransactionResultFixture(eventEncodingVersion)

data, err := encodeTransactionResult(result)
require.Nil(t, err)

var decodedResult types.StorableTransactionResult
err = decodeTransactionResult(&decodedResult, data)
require.Nil(t, err)

assert.Equal(t, result, decodedResult)
assert.Equal(t, result, decodedResult)
})
}

test(entities.EventEncodingVersion_CCF_V0)
test(entities.EventEncodingVersion_JSON_CDC_V0)
}

func TestEncodeBlock(t *testing.T) {
Expand Down Expand Up @@ -115,19 +126,29 @@ func TestEncodeEvents(t *testing.T) {

t.Parallel()

event1, _ := convert.SDKEventToFlow(test.EventGenerator().New())
event2, _ := convert.SDKEventToFlow(test.EventGenerator().New())
test := func(eventEncodingVersion entities.EventEncodingVersion) {

events := []flowgo.Event{
event1,
event2,
}
t.Run(eventEncodingVersion.String(), func(t *testing.T) {
t.Parallel()

data, err := encodeEvents(events)
require.Nil(t, err)
event1, _ := convert.SDKEventToFlow(test.EventGenerator(eventEncodingVersion).New())
event2, _ := convert.SDKEventToFlow(test.EventGenerator(eventEncodingVersion).New())

var decodedEvents []flowgo.Event
err = decodeEvents(&decodedEvents, data)
require.Nil(t, err)
assert.Equal(t, events, decodedEvents)
events := []flowgo.Event{
event1,
event2,
}

data, err := encodeEvents(events)
require.Nil(t, err)

var decodedEvents []flowgo.Event
err = decodeEvents(&decodedEvents, data)
require.Nil(t, err)
assert.Equal(t, events, decodedEvents)
})
}

test(entities.EventEncodingVersion_CCF_V0)
test(entities.EventEncodingVersion_JSON_CDC_V0)
}
Loading

0 comments on commit 60391e4

Please sign in to comment.