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

Update cadence version to secure-cadence-m4 #287

Merged
merged 3 commits into from
Apr 22, 2022
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
72 changes: 36 additions & 36 deletions lib/go/templates/internal/assets/assets.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/go/templates/manifest.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
{
"id": "SCO.03",
"name": "Register Node",
"source": "import FlowStakingCollection from 0x8d0e87b65159ae63\n\n/// Registers a delegator in the staking collection resource\n/// for the specified node information and the amount of tokens to commit\n\ntransaction(id: String,\n role: UInt8,\n networkingAddress: String,\n networkingKey: String,\n stakingKey: String,\n amount: UFix64,\n publicKeys: [String]?) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.registerNode(\n id: id,\n role: role,\n networkingAddress: networkingAddress,\n networkingKey: networkingKey,\n stakingKey: stakingKey,\n amount: amount,\n payer: account) \n {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys! {\n machineAccount.addPublicKey(key.decodeHex())\n }\n }\n }\n}\n",
"source": "import Crypto\nimport FlowStakingCollection from 0x8d0e87b65159ae63\n\n/// Registers a delegator in the staking collection resource\n/// for the specified node information and the amount of tokens to commit\n\ntransaction(id: String,\n role: UInt8,\n networkingAddress: String,\n networkingKey: String,\n stakingKey: String,\n amount: UFix64,\n publicKeys: [Crypto.KeyListEntry]?) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.registerNode(\n id: id,\n role: role,\n networkingAddress: networkingAddress,\n networkingKey: networkingKey,\n stakingKey: stakingKey,\n amount: amount,\n payer: account) \n {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys! {\n machineAccount.keys.add(publicKey: key.publicKey, hashAlgorithm: key.hashAlgorithm, weight: key.weight)\n }\n }\n }\n}\n",
"arguments": [
{
"type": "String",
Expand Down Expand Up @@ -619,12 +619,12 @@
}
],
"network": "mainnet",
"hash": "99997236b6d76caa298331d5cef77cbdf83c1af64584ece537a780ba4ac46883"
"hash": "79de7119aea61bdafb39cc3d1f4fa17ca802c2732726a86d2c636dbc19808b68"
},
{
"id": "SCO.04",
"name": "Create Machine Account",
"source": "import FlowStakingCollection from 0x8d0e87b65159ae63\n\n/// Creates a machine account for a node that is already in the staking collection\n/// and adds public keys to the new account\n\ntransaction(nodeID: String, publicKeys: [String]) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys! {\n machineAccount.addPublicKey(key.decodeHex())\n }\n } else {\n panic(\"Could not create a machine account for the node\")\n }\n }\n}\n",
"source": "import Crypto\nimport FlowStakingCollection from 0x8d0e87b65159ae63\n\n/// Creates a machine account for a node that is already in the staking collection\n/// and adds public keys to the new account\n\ntransaction(nodeID: String, publicKeys: [Crypto.KeyListEntry]) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys {\n machineAccount.keys.add(publicKey: key.publicKey, hashAlgorithm: key.hashAlgorithm, weight: key.weight)\n }\n } else {\n panic(\"Could not create a machine account for the node\")\n }\n }\n}\n",
"arguments": [
{
"type": "String",
Expand Down Expand Up @@ -676,7 +676,7 @@
}
],
"network": "mainnet",
"hash": "c2442b498eea025099815ea613d6407407192dc12ad70e1a4f47936db804a841"
"hash": "dd3b327b09087ea7f8e92a22a6b04a3c6ca33b868b430c4f15f251658c38c1b7"
},
{
"id": "SCO.05",
Expand Down
8 changes: 4 additions & 4 deletions lib/go/templates/manifest.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
{
"id": "SCO.03",
"name": "Register Node",
"source": "import FlowStakingCollection from 0x95e019a17d0e23d7\n\n/// Registers a delegator in the staking collection resource\n/// for the specified node information and the amount of tokens to commit\n\ntransaction(id: String,\n role: UInt8,\n networkingAddress: String,\n networkingKey: String,\n stakingKey: String,\n amount: UFix64,\n publicKeys: [String]?) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.registerNode(\n id: id,\n role: role,\n networkingAddress: networkingAddress,\n networkingKey: networkingKey,\n stakingKey: stakingKey,\n amount: amount,\n payer: account) \n {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys! {\n machineAccount.addPublicKey(key.decodeHex())\n }\n }\n }\n}\n",
"source": "import Crypto\nimport FlowStakingCollection from 0x95e019a17d0e23d7\n\n/// Registers a delegator in the staking collection resource\n/// for the specified node information and the amount of tokens to commit\n\ntransaction(id: String,\n role: UInt8,\n networkingAddress: String,\n networkingKey: String,\n stakingKey: String,\n amount: UFix64,\n publicKeys: [Crypto.KeyListEntry]?) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.registerNode(\n id: id,\n role: role,\n networkingAddress: networkingAddress,\n networkingKey: networkingKey,\n stakingKey: stakingKey,\n amount: amount,\n payer: account) \n {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys! {\n machineAccount.keys.add(publicKey: key.publicKey, hashAlgorithm: key.hashAlgorithm, weight: key.weight)\n }\n }\n }\n}\n",
"arguments": [
{
"type": "String",
Expand Down Expand Up @@ -619,12 +619,12 @@
}
],
"network": "testnet",
"hash": "f47efa834bc0559afae9a660b2efefddd0c6dc6e1bbcf9c3994e45ea9e5135ec"
"hash": "9246ec9b7a5c81151156e7c2f6d356f68b1b884f88728daca46b968d9a46cd5a"
},
{
"id": "SCO.04",
"name": "Create Machine Account",
"source": "import FlowStakingCollection from 0x95e019a17d0e23d7\n\n/// Creates a machine account for a node that is already in the staking collection\n/// and adds public keys to the new account\n\ntransaction(nodeID: String, publicKeys: [String]) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys! {\n machineAccount.addPublicKey(key.decodeHex())\n }\n } else {\n panic(\"Could not create a machine account for the node\")\n }\n }\n}\n",
"source": "import Crypto\nimport FlowStakingCollection from 0x95e019a17d0e23d7\n\n/// Creates a machine account for a node that is already in the staking collection\n/// and adds public keys to the new account\n\ntransaction(nodeID: String, publicKeys: [Crypto.KeyListEntry]) {\n \n let stakingCollectionRef: \u0026FlowStakingCollection.StakingCollection\n\n prepare(account: AuthAccount) {\n self.stakingCollectionRef = account.borrow\u003c\u0026FlowStakingCollection.StakingCollection\u003e(from: FlowStakingCollection.StakingCollectionStoragePath)\n ?? panic(\"Could not borrow ref to StakingCollection\")\n\n if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {\n if publicKeys == nil || publicKeys!.length == 0 {\n panic(\"Cannot provide zero keys for the machine account\")\n }\n for key in publicKeys {\n machineAccount.keys.add(publicKey: key.publicKey, hashAlgorithm: key.hashAlgorithm, weight: key.weight)\n }\n } else {\n panic(\"Could not create a machine account for the node\")\n }\n }\n}\n",
"arguments": [
{
"type": "String",
Expand Down Expand Up @@ -676,7 +676,7 @@
}
],
"network": "testnet",
"hash": "e79df145af42488e3da1d1b2e50a38a2084229896d670884f278a2119dc3bf9e"
"hash": "86c69d731560f3bff549c5f180eb4219bfe650ae4efec8e0c5b5ad3ebed54a92"
},
{
"id": "SCO.05",
Expand Down
3 changes: 2 additions & 1 deletion lib/go/test/epoch_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"fmt"
sdktemplates "github.com/onflow/flow-go-sdk/templates"
"testing"

"github.com/onflow/cadence"
Expand Down Expand Up @@ -265,7 +266,7 @@ func registerNodeWithSetupAccount(t *testing.T,
) {

publicKeys := make([]cadence.Value, 1)
publicKeys[0] = bytesToCadenceArray(publicKey.Encode())
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(publicKey)

cadencePublicKeys := cadence.NewArray(publicKeys)

Expand Down
4 changes: 2 additions & 2 deletions lib/go/test/flow_idtable_staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,8 @@ func TestIDTableStaking(t *testing.T) {
false,
)

rewards[adminID] = rewards[adminID].Minus(nil, interpreter.NewUFix64ValueWithInteger(newCommitAmount)).(interpreter.UFix64Value)
committed[adminID] = committed[adminID].Plus(nil, interpreter.NewUFix64ValueWithInteger(newCommitAmount)).(interpreter.UFix64Value)
rewards[adminID] = rewards[adminID].Minus(nil, interpreter.NewUFix64ValueWithInteger(nil, func() uint64 { return newCommitAmount })).(interpreter.UFix64Value)
committed[adminID] = committed[adminID].Plus(nil, interpreter.NewUFix64ValueWithInteger(nil, func() uint64 { return newCommitAmount })).(interpreter.UFix64Value)

result := executeScriptAndCheck(t, b, templates.GenerateGetRewardBalanceScript(env), [][]byte{jsoncdc.MustEncode(cadence.String(adminID))})
assertEqual(t, CadenceUFix64(rewards[adminID].String()), result)
Expand Down
28 changes: 14 additions & 14 deletions lib/go/test/flow_lockedtokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestLockedTokensStaker(t *testing.T) {

publicKeys := make([]cadence.Value, 1)

publicKeys[0] = bytesToCadenceArray(IDTableAccountKey.Encode())
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(IDTableAccountKey)

cadencePublicKeys := cadence.NewArray(publicKeys)
cadenceCode := bytesToCadenceArray(IDTableCode)
Expand Down Expand Up @@ -95,8 +95,8 @@ func TestLockedTokensStaker(t *testing.T) {
// Create new keys for the user account
joshKey, joshSigner := accountKeys.NewWithSigner()

adminPublicKey := bytesToCadenceArray(adminAccountKey.Encode())
joshPublicKey := bytesToCadenceArray(joshKey.Encode())
adminPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(adminAccountKey)
joshPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(joshKey)

var joshSharedAddress flow.Address
var joshAddress flow.Address
Expand Down Expand Up @@ -633,7 +633,7 @@ func TestLockedTokensDelegator(t *testing.T) {

publicKeys := make([]cadence.Value, 1)

publicKeys[0] = bytesToCadenceArray(IDTableAccountKey.Encode())
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(IDTableAccountKey)

cadencePublicKeys := cadence.NewArray(publicKeys)
cadenceCode := bytesToCadenceArray(IDTableCode)
Expand Down Expand Up @@ -700,8 +700,8 @@ func TestLockedTokensDelegator(t *testing.T) {
// Create new keys for the user account
joshKey, joshSigner := accountKeys.NewWithSigner()

adminPublicKey := bytesToCadenceArray(adminAccountKey.Encode())
joshPublicKey := bytesToCadenceArray(joshKey.Encode())
adminPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(adminAccountKey)
joshPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(joshKey)

var joshSharedAddress flow.Address
var joshAddress flow.Address
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func TestCustodyProviderAccountCreation(t *testing.T) {

publicKeys := make([]cadence.Value, 1)

publicKeys[0] = bytesToCadenceArray(IDTableAccountKey.Encode())
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(IDTableAccountKey)

cadencePublicKeys := cadence.NewArray(publicKeys)
cadenceCode := bytesToCadenceArray(IDTableCode)
Expand Down Expand Up @@ -1203,8 +1203,8 @@ func TestCustodyProviderAccountCreation(t *testing.T) {
// Create new keys for the user account
joshKey, _ := accountKeys.NewWithSigner()

adminPublicKey := bytesToCadenceArray(adminAccountKey.Encode())
joshPublicKey := bytesToCadenceArray(joshKey.Encode())
adminPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(adminAccountKey)
joshPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(joshKey)

var joshSharedAddress flow.Address
var joshAddress flow.Address
Expand Down Expand Up @@ -1258,7 +1258,7 @@ func TestCustodyProviderAccountCreation(t *testing.T) {
maxKey, maxSigner := accountKeys.NewWithSigner()
maxAddress, _ := b.CreateAccount([]*flow.AccountKey{maxKey}, nil)

maxPublicKey := bytesToCadenceArray(maxKey.Encode())
maxPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(maxKey)

var maxSharedAddress flow.Address

Expand Down Expand Up @@ -1452,8 +1452,8 @@ func TestLockedTokensRealStaking(t *testing.T) {
// Create new keys for the user account
joshKey, joshSigner := accountKeys.NewWithSigner()

adminPublicKey := bytesToCadenceArray(adminAccountKey.Encode())
joshPublicKey := bytesToCadenceArray(joshKey.Encode())
adminPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(adminAccountKey)
joshPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(joshKey)

var joshSharedAddress flow.Address
var joshAddress flow.Address
Expand Down Expand Up @@ -1782,8 +1782,8 @@ func TestLockedTokensRealDelegating(t *testing.T) {
// Create new keys for the user account
joshKey, joshSigner := accountKeys.NewWithSigner()

adminPublicKey := bytesToCadenceArray(adminAccountKey.Encode())
joshPublicKey := bytesToCadenceArray(joshKey.Encode())
adminPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(adminAccountKey)
joshPublicKey := sdktemplates.AccountKeyToCadenceCryptoKey(joshKey)

var joshSharedAddress flow.Address
var joshAddress flow.Address
Expand Down
14 changes: 5 additions & 9 deletions lib/go/test/flow_stakingcollection_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package test

import (
"encoding/hex"
"fmt"
sdktemplates "github.com/onflow/flow-go-sdk/templates"
"testing"

"github.com/onflow/cadence"
Expand Down Expand Up @@ -621,8 +621,7 @@ func TestStakingCollectionRegisterNode(t *testing.T) {

publicKeys := make([]cadence.Value, 1)
machineAccountKey, _ := accountKeys.NewWithSigner()
machineAccountKeyString := hex.EncodeToString(machineAccountKey.Encode())
publicKeys[0] = CadenceString(machineAccountKeyString)
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(machineAccountKey)
cadencePublicKeys := cadence.NewArray(publicKeys)

t.Run("Should be able to register a second node and delegator in the staking collection", func(t *testing.T) {
Expand Down Expand Up @@ -886,8 +885,7 @@ func TestStakingCollectionCreateMachineAccountForExistingNode(t *testing.T) {

publicKeys := make([]cadence.Value, 1)
machineAccountKey, _ := accountKeys.NewWithSigner()
machineAccountKeyString := hex.EncodeToString(machineAccountKey.Encode())
publicKeys[0] = CadenceString(machineAccountKeyString)
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(machineAccountKey)
cadencePublicKeys := cadence.NewArray(publicKeys)

t.Run("Should be able to set up staking collection, which moves the node and delegator to the collection", func(t *testing.T) {
Expand Down Expand Up @@ -2811,8 +2809,7 @@ func TestStakingCollectionCreateNewTokenHolder(t *testing.T) {

publicKeys := make([]cadence.Value, 1)
newAccountKey, newAccountSigner := accountKeys.NewWithSigner()
newAccountKeyString := hex.EncodeToString(newAccountKey.Encode())
publicKeys[0] = CadenceString(newAccountKeyString)
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(newAccountKey)
cadencePublicKeys := cadence.NewArray(publicKeys)
_ = tx.AddArgument(cadencePublicKeys)

Expand Down Expand Up @@ -2940,8 +2937,7 @@ func TestStakingCollectionRegisterMultipleNodes(t *testing.T) {
if i%4+1 == 1 || i%4+1 == 2 {
publicKeys := make([]cadence.Value, 1)
machineAccountKey, _ := accountKeys.NewWithSigner()
machineAccountKeyString := hex.EncodeToString(machineAccountKey.Encode())
publicKeys[0] = CadenceString(machineAccountKeyString)
publicKeys[0] = sdktemplates.AccountKeyToCadenceCryptoKey(machineAccountKey)
machineAccountKeys[i] = cadence.NewOptional(cadence.NewArray(publicKeys))
} else {
machineAccountKeys[i] = cadence.NewOptional(nil)
Expand Down
Loading