-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make the migration commitable to master
- Loading branch information
1 parent
0d75df6
commit 6926298
Showing
4 changed files
with
59 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,13 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/onflow/cadence/runtime/common" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/onflow/flow-go-sdk/crypto" | ||
|
||
"github.com/onflow/flow-go/cmd/util/ledger/util" | ||
"github.com/onflow/flow-go/cmd/util/ledger/util/registers" | ||
"github.com/onflow/flow-go/fvm" | ||
"github.com/onflow/flow-go/fvm/systemcontracts" | ||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
func TestCoreContractsKeys(t *testing.T) { | ||
func Test_fail_if_migration_enabled(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := zerolog.New(zerolog.NewTestWriter(t)) | ||
|
||
// Get the old payloads | ||
payloads, err := util.PayloadsFromEmulatorSnapshot(snapshotPath) | ||
require.NoError(t, err) | ||
|
||
registersByAccount, err := registers.NewByAccountFromPayloads(payloads) | ||
require.NoError(t, err) | ||
|
||
chainID := flow.Emulator | ||
sc := systemcontracts.SystemContractsForChain(chainID) | ||
serviceAccountAddress := sc.FlowServiceAccount.Address | ||
|
||
serviceRegisters := registersByAccount.AccountRegisters(string(serviceAccountAddress.Bytes())) | ||
|
||
pk, err := crypto.GeneratePrivateKey(crypto.ECDSA_P256, makeSeed(t)) | ||
require.NoError(t, err) | ||
expectedKey := pk.PublicKey() | ||
rwf := &testReportWriterFactory{} | ||
|
||
mig := NewAddKeyMigration( | ||
chainID, | ||
expectedKey, | ||
rwf, | ||
) | ||
defer func() { | ||
err := mig.Close() | ||
require.NoError(t, err) | ||
}() | ||
|
||
err = mig.InitMigration(log, registersByAccount, 1) | ||
require.NoError(t, err) | ||
|
||
ctx := context.Background() | ||
err = mig.MigrateAccount(ctx, common.Address(serviceAccountAddress), serviceRegisters) | ||
require.NoError(t, err) | ||
|
||
// Create all the runtime components we need for the migration | ||
migrationRuntime, err := NewInterpreterMigrationRuntime( | ||
serviceRegisters, | ||
chainID, | ||
InterpreterMigrationRuntimeConfig{}, | ||
) | ||
require.NoError(t, err) | ||
|
||
// The last key should be the one we added | ||
keys, err := migrationRuntime.Accounts.GetPublicKeyCount(serviceAccountAddress) | ||
require.NoError(t, err) | ||
|
||
key, err := migrationRuntime.Accounts.GetPublicKey(serviceAccountAddress, keys-1) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, expectedKey.String(), key.PublicKey.String()) | ||
require.Equal(t, fvm.AccountKeyWeightThreshold, key.Weight) | ||
} | ||
|
||
func Test_DO_NOT_MERGE(t *testing.T) { | ||
t.Parallel() | ||
// this branch should not be merged to master | ||
// This is only to be used for migration mainnet testing | ||
t.Fail() | ||
} | ||
|
||
func makeSeed(t *testing.T) []byte { | ||
seed := make([]byte, 32) | ||
_, err := rand.Read(seed) | ||
require.NoError(t, err) | ||
return seed | ||
// prevent merging this to master branch if enabled | ||
if IAmSureIWantToRunThisMigration { | ||
t.Fail() | ||
} | ||
} |