github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/executiondatasync/execution_data/execution_data_test.go (about) 1 package execution_data_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/module/executiondatasync/execution_data" 10 ) 11 12 func TestConvertTransactionResults(t *testing.T) { 13 t.Parallel() 14 15 t.Run("empty", func(t *testing.T) { 16 assert.Nil(t, execution_data.ConvertTransactionResults(nil)) 17 18 var results []flow.TransactionResult 19 assert.Nil(t, execution_data.ConvertTransactionResults(results)) 20 21 results = make([]flow.TransactionResult, 0) 22 assert.Nil(t, execution_data.ConvertTransactionResults(results)) 23 }) 24 25 t.Run("non-empty", func(t *testing.T) { 26 results := []flow.TransactionResult{ 27 { 28 TransactionID: flow.Identifier{1, 2, 3}, 29 ComputationUsed: 100, 30 MemoryUsed: 1000, 31 }, 32 { 33 TransactionID: flow.Identifier{4, 5, 6}, 34 ComputationUsed: 200, 35 MemoryUsed: 2000, 36 ErrorMessage: "some error", 37 }, 38 } 39 expected := []flow.LightTransactionResult{ 40 { 41 TransactionID: flow.Identifier{1, 2, 3}, 42 ComputationUsed: 100, 43 Failed: false, 44 }, 45 { 46 TransactionID: flow.Identifier{4, 5, 6}, 47 ComputationUsed: 200, 48 Failed: true, 49 }, 50 } 51 52 converted := execution_data.ConvertTransactionResults(results) 53 assert.Equal(t, len(results), len(converted)) 54 55 for i, e := range expected { 56 assert.Equal(t, e, converted[i]) 57 assert.Equal(t, e.TransactionID, converted[i].TransactionID) 58 assert.Equal(t, e.ComputationUsed, converted[i].ComputationUsed) 59 assert.Equal(t, e.Failed, converted[i].Failed) 60 } 61 }) 62 }