Skip to content

Commit

Permalink
fix the decoding of Flow type IDs by importing Cadence's type ID decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jan 18, 2021
1 parent c781ad7 commit e048a48
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
26 changes: 26 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Flow Go SDK
*
* Copyright 2019-2021 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package flow

import (
// NOTE: always import Cadence's stdlib package,
// as it registers the type ID decoder for the Flow types,
// e.g. `flow.AccountCreated`
_ "github.com/onflow/cadence/runtime/stdlib"
)
36 changes: 36 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Flow Go SDK
*
* Copyright 2019-2020 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package flow_test

import (
"testing"

"github.com/onflow/cadence/runtime/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/onflow/flow-go-sdk"
)

func TestDecodeFlowTypeID(t *testing.T) {
location, qualifiedIdentifier, err := common.DecodeTypeID(flow.EventAccountCreated)
require.NoError(t, err)
assert.Equal(t, common.LocationID("flow"), location.ID())
assert.Equal(t, "AccountCreated", qualifiedIdentifier)
}
1 change: 0 additions & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
// List of built-in account event types.
const (
EventAccountCreated string = "flow.AccountCreated"
EventAccountUpdated string = "flow.AccountUpdated"
)

type Event struct {
Expand Down

0 comments on commit e048a48

Please sign in to comment.