fix verifreg test; add VerifierRootKey() and Account() ensemble opts.
This commit is contained in:
parent
eb5a263d74
commit
d2ff0cd88e
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
"github.com/filecoin-project/go-state-types/exitcode"
|
"github.com/filecoin-project/go-state-types/exitcode"
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
"github.com/filecoin-project/go-storedcounter"
|
"github.com/filecoin-project/go-storedcounter"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/api/v1api"
|
"github.com/filecoin-project/lotus/api/v1api"
|
||||||
@ -122,7 +123,19 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble {
|
|||||||
err := o(&options)
|
err := o(&options)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
return &Ensemble{t: t, options: &options}
|
|
||||||
|
n := &Ensemble{t: t, options: &options}
|
||||||
|
|
||||||
|
// add accounts from ensemble options to genesis.
|
||||||
|
for _, acc := range options.accounts {
|
||||||
|
n.genesis.accounts = append(n.genesis.accounts, genesis.Actor{
|
||||||
|
Type: genesis.TAccount,
|
||||||
|
Balance: acc.initialBalance,
|
||||||
|
Meta: (&genesis.AccountMeta{Owner: acc.key.Address}).ActorMeta(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// FullNode enrolls a new full node.
|
// FullNode enrolls a new full node.
|
||||||
@ -135,8 +148,7 @@ func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble {
|
|||||||
|
|
||||||
var key *wallet.Key
|
var key *wallet.Key
|
||||||
if !n.bootstrapped && !options.balance.IsZero() {
|
if !n.bootstrapped && !options.balance.IsZero() {
|
||||||
// create a key+ddress, and assign it some FIL.
|
// create a key+address, and assign it some FIL; this will be set as the default wallet.
|
||||||
// this will be set as the default wallet.
|
|
||||||
var err error
|
var err error
|
||||||
key, err = wallet.GenerateKey(types.KTBLS)
|
key, err = wallet.GenerateKey(types.KTBLS)
|
||||||
require.NoError(n.t, err)
|
require.NoError(n.t, err)
|
||||||
@ -589,12 +601,22 @@ func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) []
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Ensemble) generateGenesis() *genesis.Template {
|
func (n *Ensemble) generateGenesis() *genesis.Template {
|
||||||
|
var verifRoot = gen.DefaultVerifregRootkeyActor
|
||||||
|
if k := n.options.verifiedRoot.key; k != nil {
|
||||||
|
verifRoot = genesis.Actor{
|
||||||
|
Type: genesis.TAccount,
|
||||||
|
Balance: n.options.verifiedRoot.initialBalance,
|
||||||
|
Meta: (&genesis.AccountMeta{Owner: k.Address}).ActorMeta(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
templ := &genesis.Template{
|
templ := &genesis.Template{
|
||||||
|
NetworkVersion: network.Version0,
|
||||||
Accounts: n.genesis.accounts,
|
Accounts: n.genesis.accounts,
|
||||||
Miners: n.genesis.miners,
|
Miners: n.genesis.miners,
|
||||||
NetworkName: "test",
|
NetworkName: "test",
|
||||||
Timestamp: uint64(time.Now().Unix() - 10000), // some time sufficiently far in the past
|
Timestamp: uint64(time.Now().Unix() - 10000), // some time sufficiently far in the past
|
||||||
VerifregRootKey: gen.DefaultVerifregRootkeyActor,
|
VerifregRootKey: verifRoot,
|
||||||
RemainderAccount: gen.DefaultRemainderAccountActor,
|
RemainderAccount: gen.DefaultRemainderAccountActor,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,13 +4,21 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EnsembleOpt func(opts *ensembleOpts) error
|
type EnsembleOpt func(opts *ensembleOpts) error
|
||||||
|
|
||||||
|
type genesisAccount struct {
|
||||||
|
key *wallet.Key
|
||||||
|
initialBalance abi.TokenAmount
|
||||||
|
}
|
||||||
|
|
||||||
type ensembleOpts struct {
|
type ensembleOpts struct {
|
||||||
pastOffset time.Duration
|
pastOffset time.Duration
|
||||||
proofType abi.RegisteredSealProof
|
proofType abi.RegisteredSealProof
|
||||||
|
verifiedRoot genesisAccount
|
||||||
|
accounts []genesisAccount
|
||||||
mockProofs bool
|
mockProofs bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,3 +41,25 @@ func MockProofs() EnsembleOpt {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VerifierRootKey specifies the key to be enlisted as the verified clients
|
||||||
|
// registry root, as well as the initial balance to be attributed during
|
||||||
|
// genesis.
|
||||||
|
func VerifierRootKey(key *wallet.Key, balance abi.TokenAmount) EnsembleOpt {
|
||||||
|
return func(opts *ensembleOpts) error {
|
||||||
|
opts.verifiedRoot.key = key
|
||||||
|
opts.verifiedRoot.initialBalance = balance
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account sets up an account at genesis with the specified key and balance.
|
||||||
|
func Account(key *wallet.Key, balance abi.TokenAmount) EnsembleOpt {
|
||||||
|
return func(opts *ensembleOpts) error {
|
||||||
|
opts.accounts = append(opts.accounts, genesisAccount{
|
||||||
|
key: key,
|
||||||
|
initialBalance: balance,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
package kit2
|
package kit2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/node"
|
"github.com/filecoin-project/lotus/node"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LatestActorsAt(upgradeHeight abi.ChainEpoch) node.Option {
|
// DefaultTestUpgradeSchedule
|
||||||
// Attention: Update this when introducing new actor versions or your tests will be sad
|
var DefaultTestUpgradeSchedule = stmgr.UpgradeSchedule{{
|
||||||
return NetworkUpgradeAt(network.Version13, upgradeHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) node.Option {
|
|
||||||
fullSchedule := stmgr.UpgradeSchedule{{
|
|
||||||
// prepare for upgrade.
|
|
||||||
Network: network.Version9,
|
Network: network.Version9,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
Migration: stmgr.UpgradeActorsV2,
|
Migration: stmgr.UpgradeActorsV2,
|
||||||
@ -32,6 +30,36 @@ func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) nod
|
|||||||
Migration: stmgr.UpgradeActorsV5,
|
Migration: stmgr.UpgradeActorsV5,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
func LatestActorsAt(upgradeHeight abi.ChainEpoch) node.Option {
|
||||||
|
// Attention: Update this when introducing new actor versions or your tests will be sad
|
||||||
|
return NetworkUpgradeAt(network.Version13, upgradeHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstantaneousNetworkVersion starts the network instantaneously at the
|
||||||
|
// specified version in height 1.
|
||||||
|
func InstantaneousNetworkVersion(version network.Version) node.Option {
|
||||||
|
// composes all migration functions
|
||||||
|
var mf stmgr.MigrationFunc = func(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, cb stmgr.ExecMonitor, oldState cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (newState cid.Cid, err error) {
|
||||||
|
var state = oldState
|
||||||
|
for _, u := range DefaultTestUpgradeSchedule {
|
||||||
|
if u.Network > version {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
state, err = u.Migration(ctx, sm, cache, cb, state, height, ts)
|
||||||
|
if err != nil {
|
||||||
|
return cid.Undef, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state, nil
|
||||||
|
}
|
||||||
|
return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{
|
||||||
|
{Network: version, Height: 1, Migration: mf},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) node.Option {
|
||||||
|
fullSchedule := stmgr.UpgradeSchedule{}
|
||||||
|
|
||||||
schedule := stmgr.UpgradeSchedule{}
|
schedule := stmgr.UpgradeSchedule{}
|
||||||
for _, upgrade := range fullSchedule {
|
for _, upgrade := range fullSchedule {
|
||||||
if upgrade.Network > version {
|
if upgrade.Network > version {
|
||||||
|
@ -2,13 +2,17 @@ package itests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg"
|
verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
lapi "github.com/filecoin-project/lotus/api"
|
lapi "github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
@ -23,101 +27,102 @@ func TestVerifiedClientTopUp(t *testing.T) {
|
|||||||
|
|
||||||
test := func(nv network.Version, shouldWork bool) func(*testing.T) {
|
test := func(nv network.Version, shouldWork bool) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
nopts := kit2.ConstructorOpts(kit2.NetworkUpgradeAt(nv, -1))
|
rootKey, err := wallet.GenerateKey(types.KTSecp256k1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
verifierKey, err := wallet.GenerateKey(types.KTSecp256k1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
verifiedClientKey, err := wallet.GenerateKey(types.KTBLS)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
bal, err := types.ParseFIL("100fil")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
node, _, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(),
|
||||||
|
kit2.VerifierRootKey(rootKey, abi.NewTokenAmount(bal.Int64())),
|
||||||
|
kit2.Account(verifierKey, abi.NewTokenAmount(bal.Int64())), // assign some balance to the verifier so they can send an AddClient message.
|
||||||
|
kit2.ConstructorOpts(kit2.InstantaneousNetworkVersion(nv)))
|
||||||
|
|
||||||
node, _, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), nopts)
|
|
||||||
ens.InterconnectAll().BeginMining(blockTime)
|
ens.InterconnectAll().BeginMining(blockTime)
|
||||||
|
|
||||||
api := node.FullNode.(*impl.FullNodeAPI)
|
api := node.FullNode.(*impl.FullNodeAPI)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
//Get VRH
|
// get VRH
|
||||||
vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{})
|
vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{})
|
||||||
if err != nil {
|
fmt.Println(vrh.String())
|
||||||
t.Fatal(err)
|
require.NoError(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
//Add verifier
|
// import the root key.
|
||||||
verifier, err := api.WalletDefaultAddress(ctx)
|
rootAddr, err := api.WalletImport(ctx, &rootKey.KeyInfo)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
// import the verifier's key.
|
||||||
|
verifierAddr, err := api.WalletImport(ctx, &verifierKey.KeyInfo)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// import the verified client's key.
|
||||||
|
verifiedClientAddr, err := api.WalletImport(ctx, &verifiedClientKey.KeyInfo)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
params, err := actors.SerializeParams(&verifreg4.AddVerifierParams{Address: verifierAddr, Allowance: big.NewInt(100000000000)})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
params, err := actors.SerializeParams(&verifreg4.AddVerifierParams{Address: verifier, Allowance: big.NewInt(100000000000)})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
|
From: rootAddr,
|
||||||
To: verifreg.Address,
|
To: verifreg.Address,
|
||||||
From: vrh,
|
|
||||||
Method: verifreg.Methods.AddVerifier,
|
Method: verifreg.Methods.AddVerifier,
|
||||||
Params: params,
|
Params: params,
|
||||||
Value: big.Zero(),
|
Value: big.Zero(),
|
||||||
}
|
}
|
||||||
|
|
||||||
sm, err := api.MpoolPushMessage(ctx, msg, nil)
|
sm, err := api.MpoolPushMessage(ctx, msg, nil)
|
||||||
if err != nil {
|
require.NoError(t, err, "AddVerifier failed")
|
||||||
t.Fatal("AddVerifier failed: ", err)
|
|
||||||
}
|
|
||||||
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
|
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
require.EqualValues(t, 0, res.Receipt.ExitCode)
|
||||||
}
|
|
||||||
if res.Receipt.ExitCode != 0 {
|
|
||||||
t.Fatal("did not successfully send message")
|
|
||||||
}
|
|
||||||
|
|
||||||
//Assign datacap to a client
|
// assign datacap to a client
|
||||||
datacap := big.NewInt(10000)
|
datacap := big.NewInt(10000)
|
||||||
clientAddress, err := api.WalletNew(ctx, types.KTBLS)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap})
|
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = &types.Message{
|
msg = &types.Message{
|
||||||
|
From: verifierAddr,
|
||||||
To: verifreg.Address,
|
To: verifreg.Address,
|
||||||
From: verifier,
|
|
||||||
Method: verifreg.Methods.AddVerifiedClient,
|
Method: verifreg.Methods.AddVerifiedClient,
|
||||||
Params: params,
|
Params: params,
|
||||||
Value: big.Zero(),
|
Value: big.Zero(),
|
||||||
}
|
}
|
||||||
|
|
||||||
sm, err = api.MpoolPushMessage(ctx, msg, nil)
|
sm, err = api.MpoolPushMessage(ctx, msg, nil)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal("AddVerifiedClient faield: ", err)
|
|
||||||
}
|
|
||||||
res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
|
res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
require.EqualValues(t, 0, res.Receipt.ExitCode)
|
||||||
}
|
|
||||||
if res.Receipt.ExitCode != 0 {
|
|
||||||
t.Fatal("did not successfully send message")
|
|
||||||
}
|
|
||||||
|
|
||||||
// check datacap balance
|
// check datacap balance
|
||||||
dcap, err := api.StateVerifiedClientStatus(ctx, clientAddress, types.EmptyTSK)
|
dcap, err := api.StateVerifiedClientStatus(ctx, verifiedClientAddr, types.EmptyTSK)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if !dcap.Equals(datacap) {
|
if !dcap.Equals(datacap) {
|
||||||
t.Fatal("")
|
t.Fatal("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to assign datacap to the same client should fail for actor v4 and below
|
// try to assign datacap to the same client should fail for actor v4 and below
|
||||||
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap})
|
params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = &types.Message{
|
msg = &types.Message{
|
||||||
|
From: verifierAddr,
|
||||||
To: verifreg.Address,
|
To: verifreg.Address,
|
||||||
From: verifier,
|
|
||||||
Method: verifreg.Methods.AddVerifiedClient,
|
Method: verifreg.Methods.AddVerifiedClient,
|
||||||
Params: params,
|
Params: params,
|
||||||
Value: big.Zero(),
|
Value: big.Zero(),
|
||||||
|
Loading…
Reference in New Issue
Block a user