Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rosetta] Test updates required for Crescendo #59

Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f8e7ff5
Updated go version, flow-go, crypto packages, removed relic
UlyanaAndrukhiv May 1, 2024
d72e0ee
Updated localnet configs, fixed localnet integration test
UlyanaAndrukhiv May 20, 2024
a21feed
Updated integration test
UlyanaAndrukhiv May 20, 2024
69750ec
Removed unnecessary comments
UlyanaAndrukhiv May 20, 2024
a265464
Returned back staticcheck for lint, updated const json formatting
UlyanaAndrukhiv May 22, 2024
4fe3dec
Updated formatting for localnet_const
UlyanaAndrukhiv May 22, 2024
bbf530f
Updated flow-go to v0.35.8
UlyanaAndrukhiv May 23, 2024
1534d72
Fixed payload hash calculating
UlyanaAndrukhiv May 24, 2024
69924e3
Added data folder removing before rosetta server build
UlyanaAndrukhiv May 24, 2024
5706d3c
Updated events fields parsing for indexing
UlyanaAndrukhiv May 27, 2024
354d85a
Added previewnet configs for rosetta, disabled outdated canary network
UlyanaAndrukhiv May 27, 2024
beaadb5
Updated parsing cadence values according to version 1.0
UlyanaAndrukhiv May 28, 2024
0eb8edb
Added previewnet config for rosetta
UlyanaAndrukhiv May 28, 2024
6c393ef
Updated localnet integration test
UlyanaAndrukhiv May 28, 2024
3607503
Updated scripts to Cadence 1.0
UlyanaAndrukhiv May 28, 2024
8a42e71
Updated basic-transfer transaction to Cadence 1.0
UlyanaAndrukhiv May 28, 2024
f325fc5
Added previewnet integration test, updated templates for Cadence scri…
UlyanaAndrukhiv May 28, 2024
0e2d49e
Added previewnet-integration-test command to makefile
UlyanaAndrukhiv May 28, 2024
5019703
Removed unused imports for previewnwt integration test, updated comma…
UlyanaAndrukhiv May 29, 2024
d724b4a
Merged with main
UlyanaAndrukhiv May 29, 2024
df294a2
Updated according to comment
UlyanaAndrukhiv May 29, 2024
cca69b1
Updated according to suggested comments
UlyanaAndrukhiv May 29, 2024
1c9eab4
Removed unused import from test, updated cmd formatting
UlyanaAndrukhiv May 29, 2024
da693fb
Updated according to comment, removed unnecessary temporary convertEx…
UlyanaAndrukhiv May 30, 2024
775884c
Updated scripts for proxy contract according to comments
UlyanaAndrukhiv Jun 4, 2024
0216b7d
Removed canary net and added Previewnet
franklywatson Jul 15, 2024
f82615a
Updated dependencies and fixed method change from cadence.event.GetFi…
franklywatson Jul 16, 2024
f180322
Made contents of script.go consistent with other Cadence 1.0 script c…
franklywatson Jul 16, 2024
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
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

all: build

relic:
./environ/build-relic.py

go-build:
go build -tags relic -o server cmd/server/server.go
go build -o server cmd/server/server.go

build: relic go-build
build: go-build

deps:
go mod download -x

lint:
@go mod tidy
@staticcheck -tags relic ./...
@staticcheck ./...

proto:
@echo ">> Generating model/model.pb.go"
Expand All @@ -29,4 +26,7 @@ integration-test-cleanup:
rm -rf flow-go

integration-test:
python3 integration_test.py
python3 integration_test.py

previewnet-integration-test:
python3 previewnet_integration_test.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ config file:
mode. During offline mode, only certain Rosetta API endpoints are
functional.

* `network: "mainnet" | "testnet" | "canary" | "localnet"`
* `network: "mainnet" | "testnet" | "previewnet" | "localnet"`

* This defines the specific Flow chain that is being used.

Expand Down
7 changes: 4 additions & 3 deletions access/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import (
"crypto/x509"
"encoding/hex"
"fmt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"math/rand"
"strconv"
"strings"
"time"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-go/crypto"
"github.com/onflow/crypto"
"github.com/onflow/flow-go/network/p2p/keyutils"
"github.com/onflow/flow/protobuf/go/flow/access"
"github.com/onflow/flow/protobuf/go/flow/entities"
Expand Down
2 changes: 1 addition & 1 deletion api/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (s *Server) getSequenceNumber(ctx context.Context, addr []byte, block *mode
if err != nil {
return 0, err
}
nonce, ok := resp.ToGoValue().(int64)
nonce, ok := resp.(cadence.Int64)
if !ok {
return 0, fmt.Errorf("failed to convert get_proxy_nonce result to int64")
}
Expand Down
24 changes: 14 additions & 10 deletions api/call_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *Server) accountPublicKeys(ctx context.Context, params map[string]interf
if err != nil {
return nil, handleExecutionErr(err, "execute get_proxy_public_key")
}
rawKey, ok := resp.ToGoValue().(string)
rawKey, ok := resp.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInternal, "failed to convert get_proxy_public_key result to string",
Expand All @@ -146,7 +146,7 @@ func (s *Server) accountPublicKeys(ctx context.Context, params map[string]interf
len(keys),
)
}
pub, err := hex.DecodeString(rawKey)
pub, err := hex.DecodeString(string(rawKey))
if err != nil {
return nil, wrapErrorf(
errInternal,
Expand Down Expand Up @@ -246,14 +246,15 @@ func (s *Server) getOnchainData(ctx context.Context, addr []byte, block []byte)
if err != nil {
return nil, handleExecutionErr(err, "execute "+scriptName)
}
fields, ok := resp.ToGoValue().([]interface{})
structValue, ok := resp.(cadence.Struct)
if !ok {
return nil, wrapErrorf(
errInternal,
"failed to convert %s result to Go slice",
"failed to convert %s result to array",
scriptName,
)
}
fields := cadence.FieldsMappedByName(structValue)
if len(fields) != 3 {
return nil, wrapErrorf(
errInternal,
Expand All @@ -262,30 +263,33 @@ func (s *Server) getOnchainData(ctx context.Context, addr []byte, block []byte)
)
}
onchain := &onchainData{}
onchain.DefaultBalance, ok = fields[0].(uint64)
defaultBalance, ok := fields["default_balance"].(cadence.UFix64)
if !ok {
return nil, wrapErrorf(
errInternal,
"expected first field of the %s result to be uint64: got %T",
scriptName, fields[0],
scriptName, fields["default_balance"],
)
}
onchain.IsProxy, ok = fields[1].(bool)
onchain.DefaultBalance = uint64(defaultBalance)
isProxy, ok := fields["is_proxy"].(cadence.Bool)
if !ok {
return nil, wrapErrorf(
errInternal,
"expected second field of the %s result to be bool: got %T",
scriptName, fields[1],
scriptName, fields["is_proxy"],
)
}
onchain.ProxyBalance, ok = fields[2].(uint64)
onchain.IsProxy = bool(isProxy)
proxyBalance, ok := fields["proxy_balance"].(cadence.UFix64)
if !ok {
return nil, wrapErrorf(
errInternal,
"expected third field of the %s result to be uint64: got %T",
scriptName, fields[2],
scriptName, fields["proxy_balance"],
)
}
onchain.ProxyBalance = uint64(proxyBalance)
return onchain, nil
}

Expand Down
61 changes: 30 additions & 31 deletions api/construction_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"math/big"
"strconv"
"strings"

Expand Down Expand Up @@ -132,14 +131,14 @@ func (s *Server) ConstructionMetadata(ctx context.Context, r *types.Construction
"failed to execute get_proxy_nonce: %s", err,
)
}
nonce, ok := resp.ToGoValue().(int64)
nonce, ok := resp.(cadence.Int64)
if !ok {
return nil, wrapErrorf(
errInternal,
"failed to convert get_proxy_nonce result to int64",
"expected type cadence.Int64 for nonce, got %T", resp,
)
}
opts.SequenceNumber = nonce
opts.SequenceNumber = int64(nonce)
}
} else {
latest := s.Index.Latest()
Expand All @@ -165,14 +164,14 @@ func (s *Server) ConstructionMetadata(ctx context.Context, r *types.Construction
"failed to execute compute_fees: %s", err,
)
}
cost, ok := resp.ToGoValue().(uint64)
cost, ok := resp.(cadence.UFix64)
if !ok {
return nil, wrapErrorf(
errInternal,
"failed to convert compute_fees result to uint64",
"expected type cadence.UFix64 for cost, got %T", resp,
)
}
opts.Fees = cost + (opts.NewAccounts * fees.MinimumAccountBalance)
opts.Fees = uint64(cost) + (opts.NewAccounts * fees.MinimumAccountBalance)
trace.SetAttributes(
ctx,
trace.String("access_api_server", client.ServerAddress()),
Expand Down Expand Up @@ -1137,7 +1136,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
update, ok := raw.ToGoValue().(bool)
update, ok := raw.(cadence.Bool)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
Expand All @@ -1153,7 +1152,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
name, ok := raw.ToGoValue().(string)
name, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
Expand All @@ -1165,7 +1164,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
code, ok := raw.ToGoValue().(string)
code, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
Expand All @@ -1177,7 +1176,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
prevKeyIndex, ok := raw.ToGoValue().(*big.Int)
prevKeyIndex, ok := raw.(cadence.Int)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to *big.Int",
Expand All @@ -1189,13 +1188,13 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
rawKey, ok := raw.ToGoValue().(string)
rawKey, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
)
}
flowKey, err := hex.DecodeString(rawKey)
flowKey, err := hex.DecodeString(string(rawKey))
if err != nil {
return nil, wrapErrorf(
errInvalidTransactionPayload,
Expand All @@ -1217,7 +1216,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
keyMessage, ok := raw.ToGoValue().(string)
keyMessage, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
Expand All @@ -1229,13 +1228,13 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
rawSignature, ok := raw.ToGoValue().(string)
rawSignature, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
)
}
keySignature, err := crypto.ConvertFlowSignature(rawSignature)
keySignature, err := crypto.ConvertFlowSignature(string(rawSignature))
if err != nil {
return nil, wrapErrorf(
errInvalidTransactionPayload,
Expand All @@ -1249,7 +1248,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
errInvalidTransactionPayload, "unable to decode transaction arg: %s", err,
)
}
keyMetadata, ok := raw.ToGoValue().(string)
keyMetadata, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
Expand All @@ -1264,7 +1263,7 @@ func decodeContractOps(txn *entities.Transaction, signed bool) (*types.Construct
"key_metadata": keyMetadata,
"key_signature": keySignature,
"new_key": hex.EncodeToString(newKey),
"prev_key_index": prevKeyIndex.Int64(),
"prev_key_index": prevKeyIndex.Value.Int64(),
},
OperationIdentifier: &types.OperationIdentifier{
Index: 0,
Expand All @@ -1289,13 +1288,13 @@ func decodeCreateAccountOps(txn *entities.Transaction, proxy bool, signed bool)
)
}
if proxy {
key, ok := raw.ToGoValue().(string)
key, ok := raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to string",
)
}
pub, err := hex.DecodeString(key)
pub, err := hex.DecodeString(string(key))
if err != nil {
return nil, wrapErrorf(
errInvalidTransactionPayload,
Expand All @@ -1316,20 +1315,20 @@ func decodeCreateAccountOps(txn *entities.Transaction, proxy bool, signed bool)
Type: opCreateProxyAccount,
})
} else {
xs, ok := raw.ToGoValue().([]interface{})
xs, ok := raw.(cadence.Array)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg to array",
)
}
for _, val := range xs {
key, ok := val.(string)
for _, val := range xs.Values {
key, ok := val.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert transaction arg elem to string",
)
}
pub, err := hex.DecodeString(key)
pub, err := hex.DecodeString(string(key))
if err != nil {
return nil, wrapErrorf(
errInvalidTransactionPayload,
Expand Down Expand Up @@ -1402,7 +1401,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
errInvalidTransactionPayload, "unable to decode sender transaction arg: %s", err,
)
}
addr, ok := raw.ToGoValue().([8]byte)
addr, ok := raw.(cadence.Address)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert sender arg to address",
Expand All @@ -1417,7 +1416,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
errInvalidTransactionPayload, "unable to decode receiver transaction arg: %s", err,
)
}
receiver, ok := raw.ToGoValue().([8]byte)
receiver, ok := raw.(cadence.Address)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert receiver arg to address",
Expand All @@ -1429,7 +1428,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
errInvalidTransactionPayload, "unable to decode amount transaction arg: %s", err,
)
}
amount, ok := raw.ToGoValue().(uint64)
amount, ok := raw.(cadence.UInt64)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert amount transaction arg to uint64",
Expand All @@ -1444,7 +1443,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
errInvalidTransactionPayload, "unable to decode nonce transaction arg: %s", err,
)
}
_, ok := raw.ToGoValue().(int64)
_, ok := raw.(cadence.Int64)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert nonce transaction arg to int64",
Expand All @@ -1456,7 +1455,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
errInvalidTransactionPayload, "unable to decode sig transaction arg: %s", err,
)
}
_, ok = raw.ToGoValue().(string)
_, ok = raw.(cadence.String)
if !ok {
return nil, wrapErrorf(
errInvalidTransactionPayload, "unable to convert sig transaction arg to string",
Expand All @@ -1470,7 +1469,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
},
Amount: &types.Amount{
Currency: flowCurrency,
Value: "-" + strconv.FormatUint(amount, 10),
Value: "-" + strconv.FormatUint(uint64(amount), 10),
},
OperationIdentifier: &types.OperationIdentifier{
Index: 0,
Expand All @@ -1483,7 +1482,7 @@ func decodeTransferOps(txn *entities.Transaction, proxy bool, signed bool) (*typ
},
Amount: &types.Amount{
Currency: flowCurrency,
Value: strconv.FormatUint(amount, 10),
Value: strconv.FormatUint(uint64(amount), 10),
},
OperationIdentifier: &types.OperationIdentifier{
Index: 1,
Expand Down
Loading