Split validation into basic/advanced
This commit is contained in:
+74
-33
@@ -23,17 +23,18 @@ func main() {
|
||||
|
||||
func testSendTx() {
|
||||
eyesCli := eyescli.NewLocalClient()
|
||||
chainID := "test_chain_id"
|
||||
bcApp := app.NewBasecoin(eyesCli)
|
||||
bcApp.SetOption("base/chainID", chainID)
|
||||
fmt.Println(bcApp.Info())
|
||||
|
||||
tPriv := tests.PrivAccountFromSecret("test")
|
||||
tPriv2 := tests.PrivAccountFromSecret("test2")
|
||||
test1PrivAcc := tests.PrivAccountFromSecret("test1")
|
||||
test2PrivAcc := tests.PrivAccountFromSecret("test2")
|
||||
|
||||
// Seed Basecoin with account
|
||||
tAcc := tPriv.Account
|
||||
tAcc.Balance = types.Coins{{"", 1000}}
|
||||
fmt.Println(bcApp.SetOption("base/chainID", "test_chain_id"))
|
||||
fmt.Println(bcApp.SetOption("base/account", string(wire.JSONBytes(tAcc))))
|
||||
test1Acc := test1PrivAcc.Account
|
||||
test1Acc.Balance = types.Coins{{"", 1000}}
|
||||
fmt.Println(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc))))
|
||||
|
||||
// Construct a SendTx signature
|
||||
tx := &types.SendTx{
|
||||
@@ -41,24 +42,24 @@ func testSendTx() {
|
||||
Gas: 0,
|
||||
Inputs: []types.TxInput{
|
||||
types.TxInput{
|
||||
Address: tPriv.Account.PubKey.Address(),
|
||||
PubKey: tPriv.Account.PubKey, // TODO is this needed?
|
||||
Address: test1PrivAcc.Account.PubKey.Address(),
|
||||
PubKey: test1PrivAcc.Account.PubKey, // TODO is this needed?
|
||||
Coins: types.Coins{{"", 1}},
|
||||
Sequence: 1,
|
||||
},
|
||||
},
|
||||
Outputs: []types.TxOutput{
|
||||
types.TxOutput{
|
||||
Address: tPriv2.Account.PubKey.Address(),
|
||||
Address: test2PrivAcc.Account.PubKey.Address(),
|
||||
Coins: types.Coins{{"", 1}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Sign request
|
||||
signBytes := tx.SignBytes("test_chain_id")
|
||||
signBytes := tx.SignBytes(chainID)
|
||||
fmt.Printf("Sign bytes: %X\n", signBytes)
|
||||
sig := tPriv.PrivKey.Sign(signBytes)
|
||||
sig := test1PrivAcc.PrivKey.Sign(signBytes)
|
||||
tx.Inputs[0].Signature = sig
|
||||
//fmt.Println("tx:", tx)
|
||||
fmt.Printf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx}))
|
||||
@@ -74,19 +75,21 @@ func testSendTx() {
|
||||
|
||||
func testGov() {
|
||||
eyesCli := eyescli.NewLocalClient()
|
||||
chainID := "test_chain_id"
|
||||
bcApp := app.NewBasecoin(eyesCli)
|
||||
bcApp.SetOption("base/chainID", chainID)
|
||||
fmt.Println(bcApp.Info())
|
||||
|
||||
tPriv := tests.PrivAccountFromSecret("test")
|
||||
valPrivKey0 := crypto.GenPrivKeyEd25519FromSecret([]byte("val0"))
|
||||
valPrivKey1 := crypto.GenPrivKeyEd25519FromSecret([]byte("val1"))
|
||||
valPrivKey2 := crypto.GenPrivKeyEd25519FromSecret([]byte("val2"))
|
||||
adminPrivAcc := tests.PrivAccountFromSecret("admin")
|
||||
val0PrivKey := crypto.GenPrivKeyEd25519FromSecret([]byte("val0"))
|
||||
val1PrivKey := crypto.GenPrivKeyEd25519FromSecret([]byte("val1"))
|
||||
val2PrivKey := crypto.GenPrivKeyEd25519FromSecret([]byte("val2"))
|
||||
|
||||
// Seed Basecoin with admin using PrivAccount
|
||||
tAcc := tPriv.Account
|
||||
adminAcc := adminPrivAcc.Account
|
||||
adminEntity := govtypes.Entity{
|
||||
Addr: tAcc.PubKey.Address(),
|
||||
PubKey: tAcc.PubKey,
|
||||
Addr: adminAcc.PubKey.Address(),
|
||||
PubKey: adminAcc.PubKey,
|
||||
}
|
||||
log := bcApp.SetOption("gov/admin", string(wire.JSONBytes(adminEntity)))
|
||||
if log != "Success" {
|
||||
@@ -95,15 +98,15 @@ func testGov() {
|
||||
|
||||
// Call InitChain to initialize the validator set
|
||||
bcApp.InitChain([]*tmsp.Validator{
|
||||
{PubKey: valPrivKey0.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: valPrivKey1.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: valPrivKey2.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: val0PrivKey.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: val1PrivKey.PubKey().Bytes(), Power: 1},
|
||||
{PubKey: val2PrivKey.PubKey().Bytes(), Power: 1},
|
||||
})
|
||||
|
||||
// Query for validator set
|
||||
res := bcApp.Query(expr.MustCompile(`x02 x01 "gov/g/validators"`))
|
||||
if res.IsErr() {
|
||||
Exit(Fmt("Failed: %v", res.Error()))
|
||||
Exit(Fmt("Failed to query validators: %v", res.Error()))
|
||||
}
|
||||
group := govtypes.Group{}
|
||||
err := wire.ReadBinaryBytes(res.Data, &group)
|
||||
@@ -111,22 +114,60 @@ func testGov() {
|
||||
Exit(Fmt("Unexpected query response bytes: %X error: %v",
|
||||
res.Data, err))
|
||||
}
|
||||
fmt.Println(">>", group)
|
||||
// fmt.Println("Initialized gov/g/validators", group)
|
||||
|
||||
// Mutate the validator set.
|
||||
proposal := govtypes.Proposal{
|
||||
ID: "my_proposal_id",
|
||||
VoteGroupID: "gov/admin",
|
||||
StartHeight: 0,
|
||||
EndHeight: 0,
|
||||
Info: &govtypes.GroupUpdateProposalInfo{
|
||||
UpdateGroupID: "gov/g/validators",
|
||||
NextVersion: 0,
|
||||
ChangedMembers: []govtypes.Member{
|
||||
{nil, 1}, // TODO Fill this out.
|
||||
},
|
||||
},
|
||||
}
|
||||
proposalTx := &govtypes.ProposalTx{
|
||||
EntityAddr: adminEntity.Addr,
|
||||
Proposal: proposal,
|
||||
}
|
||||
proposalTx.SetSignature(nil, adminPrivAcc.Sign(proposalTx.SignBytes()))
|
||||
tx := &types.AppTx{
|
||||
Fee: 1,
|
||||
Gas: 1,
|
||||
Type: app.PluginTypeByteGov, // XXX Remove typebytes?
|
||||
Input: types.TxInput{
|
||||
Address: adminEntity.Addr,
|
||||
Coins: types.Coins{{"", 1}},
|
||||
Sequence: 1,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
tx.SetSignature(nil, adminPrivAcc.Sign(tx.SignBytes(chainID)))
|
||||
res = bcApp.AppendTx(wire.BinaryBytes(struct{ types.Tx }{tx}))
|
||||
if res.IsErr() {
|
||||
Exit(Fmt("Failed to mutate validators: %v", res.Error()))
|
||||
}
|
||||
fmt.Println(res)
|
||||
|
||||
// TODO more tests...
|
||||
}
|
||||
|
||||
func testSequence() {
|
||||
eyesCli := eyescli.NewLocalClient()
|
||||
bcApp := app.NewBasecoin(eyesCli)
|
||||
chainID := "test_chain_id"
|
||||
bcApp := app.NewBasecoin(eyesCli)
|
||||
bcApp.SetOption("base/chainID", chainID)
|
||||
fmt.Println(bcApp.Info())
|
||||
|
||||
// Get the root account
|
||||
root := tests.PrivAccountFromSecret("test")
|
||||
rootAcc := root.Account
|
||||
rootAcc.Balance = types.Coins{{"", 1 << 53}}
|
||||
fmt.Println(bcApp.SetOption("base/chainID", "test_chain_id"))
|
||||
fmt.Println(bcApp.SetOption("base/account", string(wire.JSONBytes(rootAcc))))
|
||||
// Get the test account
|
||||
test1PrivAcc := tests.PrivAccountFromSecret("test1")
|
||||
test1Acc := test1PrivAcc.Account
|
||||
test1Acc.Balance = types.Coins{{"", 1 << 53}}
|
||||
fmt.Println(bcApp.SetOption("base/account", string(wire.JSONBytes(test1Acc))))
|
||||
|
||||
sequence := int(1)
|
||||
// Make a bunch of PrivAccounts
|
||||
@@ -141,8 +182,8 @@ func testSequence() {
|
||||
Gas: 2,
|
||||
Inputs: []types.TxInput{
|
||||
types.TxInput{
|
||||
Address: root.Account.PubKey.Address(),
|
||||
PubKey: root.Account.PubKey, // TODO is this needed?
|
||||
Address: test1Acc.PubKey.Address(),
|
||||
PubKey: test1Acc.PubKey, // TODO is this needed?
|
||||
Coins: types.Coins{{"", 1000002}},
|
||||
Sequence: sequence,
|
||||
},
|
||||
@@ -158,7 +199,7 @@ func testSequence() {
|
||||
|
||||
// Sign request
|
||||
signBytes := tx.SignBytes(chainID)
|
||||
sig := root.PrivKey.Sign(signBytes)
|
||||
sig := test1PrivAcc.PrivKey.Sign(signBytes)
|
||||
tx.Inputs[0].Signature = sig
|
||||
// fmt.Printf("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user