wip genesis parsing
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/examples/basecoin/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
)
|
||||
|
||||
@@ -37,4 +43,25 @@ func TestSendMsg(t *testing.T) {
|
||||
// Run a Deliver on SendMsg.
|
||||
res = tba.RunDeliverMsg(msg)
|
||||
assert.Equal(t, sdk.CodeUnrecognizedAddress, res.Code, res.Log)
|
||||
|
||||
// TODO seperate this test, need a closer on db? keep getting resource unavailable
|
||||
|
||||
// construct some genesis bytes to reflect basecoin/types/AppAccount
|
||||
pk := crypto.GenPrivKeyEd25519().PubKey()
|
||||
addr := pk.Address()
|
||||
coins, err := sdk.ParseCoins("77foocoin,99barcoin")
|
||||
require.Nil(t, err)
|
||||
baseAcc := auth.BaseAccount{
|
||||
Address: addr,
|
||||
Coins: coins,
|
||||
PubKey: pk,
|
||||
Sequence: 0,
|
||||
}
|
||||
accs := []types.AppAccount{
|
||||
{baseAcc, "foobart"},
|
||||
{baseAcc, "endofzeworld"},
|
||||
}
|
||||
bytes, err := json.MarshalIndent(&accs, "", "\t")
|
||||
_ = bytes
|
||||
// XXX test the json bytes in the InitStater
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/examples/basecoin/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@@ -28,12 +31,21 @@ func (app *BasecoinApp) initBaseAppTxDecoder() {
|
||||
})
|
||||
}
|
||||
|
||||
// used to define the custom logic for initialization
|
||||
// define the custom logic for basecoin initialization
|
||||
func (app *BasecoinApp) initBaseAppInitStater() {
|
||||
//accountMapper := app.accountMapper
|
||||
accountMapper := app.accountMapper
|
||||
app.BaseApp.SetInitStater(func(ctx sdk.Context, stateJSON []byte) sdk.Error {
|
||||
// TODO: parse JSON
|
||||
//accountMapper.SetAccount(ctx, ...)
|
||||
|
||||
var accs []*types.AppAccount
|
||||
|
||||
err := json.Unmarshal(stateJSON, &accs)
|
||||
if err != nil {
|
||||
return sdk.ErrGenesisParse("").TraceCause(err, "")
|
||||
}
|
||||
|
||||
for _, acc := range accs {
|
||||
accountMapper.SetAccount(ctx, acc)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user