Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions adapters/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,11 @@ func TestAccess(t *testing.T) {
}

func ccfEventFixture(t *testing.T) flowgo.Event {
cadenceValue, err := cadence.NewValue(2)
require.NoError(t, err)
cadenceValue := cadence.NewInt(2)

ccfEvent, err := ccf.EventsEncMode.Encode(cadenceValue)
require.NoError(t, err)

return flowgo.Event{
Payload: ccfEvent,
}
Expand Down
12 changes: 9 additions & 3 deletions adapters/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (

"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/flow-emulator/convert"
emulator "github.com/onflow/flow-emulator/emulator"
"github.com/onflow/cadence/runtime/stdlib"
sdk "github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/templates"
"github.com/onflow/flow-go/access"
Expand All @@ -34,6 +33,9 @@ import (
"github.com/rs/zerolog"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

// SDKAdapter wraps an emulated emulator and implements the RPC handlers
Expand Down Expand Up @@ -519,7 +521,11 @@ func (b *SDKAdapter) CreateAccount(ctx context.Context, publicKeys []*sdk.Accoun

for _, event := range lastResult.Events {
if event.Type == sdk.EventAccountCreated {
address = sdk.Address(event.Value.Fields[0].(cadence.Address))
addressFieldValue := cadence.SearchFieldByName(
event.Value,
stdlib.AccountEventAddressParameter.Identifier,
)
address = sdk.Address(addressFieldValue.(cadence.Address))
break
}
}
Expand Down
10 changes: 8 additions & 2 deletions emulator/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
"fmt"
"testing"

"github.com/onflow/cadence/runtime/stdlib"
"github.com/rs/zerolog"

"github.com/onflow/flow-emulator/adapters"
"github.com/onflow/flow-emulator/emulator"
"github.com/rs/zerolog"

"github.com/onflow/cadence"
flowsdk "github.com/onflow/flow-go-sdk"
Expand Down Expand Up @@ -141,7 +143,11 @@ func LastCreatedAccount(b *emulator.Blockchain, result *types.TransactionResult)
func LastCreatedAccountAddress(result *types.TransactionResult) (flowsdk.Address, error) {
for _, event := range result.Events {
if event.Type == flowsdk.EventAccountCreated {
return flowsdk.Address(event.Value.Fields[0].(cadence.Address)), nil
addressFieldValue := cadence.SearchFieldByName(
event.Value,
stdlib.AccountEventAddressParameter.Identifier,
)
return flowsdk.Address(addressFieldValue.(cadence.Address)), nil
}
}

Expand Down
25 changes: 19 additions & 6 deletions emulator/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
"fmt"
"testing"

"github.com/rs/zerolog"

"github.com/onflow/flow-emulator/adapters"
"github.com/onflow/flow-emulator/emulator"
"github.com/rs/zerolog"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-go-sdk/templates"
Expand Down Expand Up @@ -151,11 +152,20 @@ func TestEventEmitted(t *testing.T) {
assert.Equal(t, string(expectedType), actualEvent.Type)
assert.Equal(t, expectedID, actualEvent.ID())
assert.Equal(t, "x", decodedEventType.Fields[0].Identifier)
assert.Equal(t, cadence.NewInt(1), decodedEvent.Fields[0])
assert.Equal(t, "y", decodedEventType.Fields[1].Identifier)
assert.Equal(t, cadence.NewInt(2), decodedEvent.Fields[1])

events, err = adapter.GetEventsForBlockIDs(context.Background(), string(expectedType), []flowsdk.Identifier{flowsdk.Identifier(block.Header.ID())})
fields := cadence.FieldsMappedByName(decodedEvent)

assert.Equal(t, cadence.NewInt(1), fields["x"])
assert.Equal(t, cadence.NewInt(2), fields["y"])

events, err = adapter.GetEventsForBlockIDs(
context.Background(),
string(expectedType),
[]flowsdk.Identifier{
flowsdk.Identifier(block.Header.ID()),
},
)
require.NoError(t, err)
require.Len(t, events, 1)

Expand All @@ -167,9 +177,12 @@ func TestEventEmitted(t *testing.T) {
assert.Equal(t, string(expectedType), actualEvent.Type)
assert.Equal(t, expectedID, actualEvent.ID())
assert.Equal(t, "x", decodedEventType.Fields[0].Identifier)
assert.Equal(t, cadence.NewInt(1), decodedEvent.Fields[0])
assert.Equal(t, "y", decodedEventType.Fields[1].Identifier)
assert.Equal(t, cadence.NewInt(2), decodedEvent.Fields[1])

fields = cadence.FieldsMappedByName(decodedEvent)

assert.Equal(t, cadence.NewInt(1), fields["x"])
assert.Equal(t, cadence.NewInt(2), fields["y"])

})
}
15 changes: 12 additions & 3 deletions emulator/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1457,8 +1457,12 @@ func TestGetTransactionResult(t *testing.T) {
assert.Equal(t, tx.ID(), event.TransactionID)
assert.Equal(t, string(eventType), event.Type)
assert.Equal(t, 0, event.EventIndex)
assert.Equal(t, 1, len(event.Value.Fields))
assert.Equal(t, cadence.NewInt(2), event.Value.Fields[0])
fields := cadence.FieldsMappedByName(event.Value)
assert.Len(t, fields, 1)
assert.Equal(t,
cadence.NewInt(2),
fields["count"],
)
}

// TestGetTxByBlockIDMethods tests the GetTransactionByBlockID and GetTransactionResultByBlockID
Expand Down Expand Up @@ -2076,8 +2080,13 @@ func IncrementHelper(t *testing.T, b emulator.Emulator, adapter *adapters.SDKAda
assert.Equal(t, tx.ID(), event.TransactionID)
assert.Equal(t, string(eventType), event.Type)
assert.Equal(t, 0, event.EventIndex)
assert.Equal(t, cadence.NewInt(expected), event.Value.Fields[0])

fields := cadence.FieldsMappedByName(event.Value)
assert.Len(t, fields, 1)
assert.Equal(t,
cadence.NewInt(expected),
fields["count"],
)
}

func TestRollbackTransaction(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/onflow/flow-emulator

go 1.21
go 1.20

require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
Expand All @@ -12,11 +12,11 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/improbable-eng/grpc-web v0.15.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/onflow/cadence v1.0.0-preview.23
github.com/onflow/cadence v1.0.0-preview.24
github.com/onflow/crypto v0.25.1
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240429192223-e696a8e439b5
github.com/onflow/flow-go v0.34.0-crescendo-preview.17
github.com/onflow/flow-go-sdk v1.0.0-preview.22
github.com/onflow/flow-go v0.34.0-crescendo-preview.10-staged-contracts-3.0.20240501173610-13b1393dd6b7
github.com/onflow/flow-go-sdk v1.0.0-preview.24
github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240429184308-40c3de711140
github.com/onflow/flow/protobuf/go/flow v0.4.1-0.20240412170550-911321113030
github.com/prometheus/client_golang v1.18.0
Expand Down Expand Up @@ -94,7 +94,7 @@ require (
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/boxo v0.19.0 // indirect
Comment thread
turbolent marked this conversation as resolved.
github.com/ipfs/boxo v0.17.1-0.20240131173518-89bceff34bf1 // indirect
github.com/ipfs/go-block-format v0.2.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down Expand Up @@ -133,7 +133,7 @@ require (
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onflow/atree v0.6.1-0.20240416233652-f4568c0c03df // indirect
github.com/onflow/atree v0.7.0-rc.1 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.2-0.20240429192223-e696a8e439b5 // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240424211859-3ff4c0fe2a1e // indirect
github.com/onflow/flow-ft/lib/go/templates v0.7.1-0.20240424211859-3ff4c0fe2a1e // indirect
Expand Down
Loading