Test outgoing ibc packets add to the chain credit properly
This commit is contained in:
parent
555e0d8ec8
commit
0c5f0bdf77
|
@ -12,6 +12,8 @@ import (
|
||||||
|
|
||||||
// GetAccount - Get account from store and address
|
// GetAccount - Get account from store and address
|
||||||
func GetAccount(store state.SimpleDB, addr basecoin.Actor) (Account, error) {
|
func GetAccount(store state.SimpleDB, addr basecoin.Actor) (Account, error) {
|
||||||
|
// if the actor is another chain, we use one address for the chain....
|
||||||
|
addr = ChainAddr(addr)
|
||||||
acct, err := loadAccount(store, addr.Bytes())
|
acct, err := loadAccount(store, addr.Bytes())
|
||||||
|
|
||||||
// for empty accounts, don't return an error, but rather an empty account
|
// for empty accounts, don't return an error, but rather an empty account
|
||||||
|
@ -23,12 +25,18 @@ func GetAccount(store state.SimpleDB, addr basecoin.Actor) (Account, error) {
|
||||||
|
|
||||||
// CheckCoins makes sure there are funds, but doesn't change anything
|
// CheckCoins makes sure there are funds, but doesn't change anything
|
||||||
func CheckCoins(store state.SimpleDB, addr basecoin.Actor, coins Coins) (Coins, error) {
|
func CheckCoins(store state.SimpleDB, addr basecoin.Actor, coins Coins) (Coins, error) {
|
||||||
|
// if the actor is another chain, we use one address for the chain....
|
||||||
|
addr = ChainAddr(addr)
|
||||||
|
|
||||||
acct, err := updateCoins(store, addr, coins)
|
acct, err := updateCoins(store, addr, coins)
|
||||||
return acct.Coins, err
|
return acct.Coins, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeCoins changes the money, returns error if it would be negative
|
// ChangeCoins changes the money, returns error if it would be negative
|
||||||
func ChangeCoins(store state.SimpleDB, addr basecoin.Actor, coins Coins) (Coins, error) {
|
func ChangeCoins(store state.SimpleDB, addr basecoin.Actor, coins Coins) (Coins, error) {
|
||||||
|
// if the actor is another chain, we use one address for the chain....
|
||||||
|
addr = ChainAddr(addr)
|
||||||
|
|
||||||
acct, err := updateCoins(store, addr, coins)
|
acct, err := updateCoins(store, addr, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return acct.Coins, err
|
return acct.Coins, err
|
||||||
|
@ -55,9 +63,6 @@ func ChainAddr(addr basecoin.Actor) basecoin.Actor {
|
||||||
//
|
//
|
||||||
// it doesn't save anything, that is up to you to decide (Check/Change Coins)
|
// it doesn't save anything, that is up to you to decide (Check/Change Coins)
|
||||||
func updateCoins(store state.SimpleDB, addr basecoin.Actor, coins Coins) (acct Account, err error) {
|
func updateCoins(store state.SimpleDB, addr basecoin.Actor, coins Coins) (acct Account, err error) {
|
||||||
// if the actor is another chain, we use one address for the chain....
|
|
||||||
addr = ChainAddr(addr)
|
|
||||||
|
|
||||||
acct, err = loadAccount(store, addr.Bytes())
|
acct, err = loadAccount(store, addr.Bytes())
|
||||||
// we can increase an empty account...
|
// we can increase an empty account...
|
||||||
if IsNoAccountErr(err) && coins.IsPositive() {
|
if IsNoAccountErr(err) && coins.IsPositive() {
|
||||||
|
|
|
@ -391,6 +391,26 @@ func TestIBCPostPacket(t *testing.T) {
|
||||||
_, err := app.DeliverTx(ctx, store, tx)
|
_, err := app.DeliverTx(ctx, store, tx)
|
||||||
require.Nil(err, "%+v", err)
|
require.Nil(err, "%+v", err)
|
||||||
|
|
||||||
|
// set up a rich guy on this chain
|
||||||
|
wealth := coin.Coins{{"btc", 300}, {"eth", 2000}, {"ltc", 5000}}
|
||||||
|
rich := coin.NewAccountWithKey(wealth)
|
||||||
|
_, err = app.SetOption(log.NewNopLogger(), store,
|
||||||
|
"coin", "account", rich.MakeOption())
|
||||||
|
require.Nil(err, "%+v", err)
|
||||||
|
|
||||||
|
// sends money to another guy on a different chain, now other chain has credit
|
||||||
|
buddy := basecoin.Actor{ChainID: otherID, App: auth.NameSigs, Address: []byte("dude")}
|
||||||
|
outTx := coin.NewSendOneTx(rich.Actor(), buddy, wealth)
|
||||||
|
_, err = app.DeliverTx(ctx.WithPermissions(rich.Actor()), store, outTx)
|
||||||
|
require.Nil(err, "%+v", err)
|
||||||
|
|
||||||
|
// make sure the money moved to the other chain...
|
||||||
|
cstore := stack.PrefixedStore(coin.NameCoin, store)
|
||||||
|
acct, err := coin.GetAccount(cstore, coin.ChainAddr(buddy))
|
||||||
|
require.Nil(err, "%+v", err)
|
||||||
|
require.Equal(wealth, acct.Coins)
|
||||||
|
|
||||||
|
// these are the people for testing incoming ibc from the other chain
|
||||||
recipient := basecoin.Actor{ChainID: ourID, App: auth.NameSigs, Address: []byte("bar")}
|
recipient := basecoin.Actor{ChainID: ourID, App: auth.NameSigs, Address: []byte("bar")}
|
||||||
sender := basecoin.Actor{ChainID: otherID, App: auth.NameSigs, Address: []byte("foo")}
|
sender := basecoin.Actor{ChainID: otherID, App: auth.NameSigs, Address: []byte("foo")}
|
||||||
coinTx := coin.NewSendOneTx(
|
coinTx := coin.NewSendOneTx(
|
||||||
|
@ -399,14 +419,6 @@ func TestIBCPostPacket(t *testing.T) {
|
||||||
coin.Coins{{"eth", 100}, {"ltc", 300}},
|
coin.Coins{{"eth", 100}, {"ltc", 300}},
|
||||||
)
|
)
|
||||||
|
|
||||||
// set some cash on this chain (TODO: via set options...)
|
|
||||||
otherAddr := coin.ChainAddr(sender)
|
|
||||||
acct := coin.Account{
|
|
||||||
Coins: coin.Coins{{"btc", 300}, {"eth", 2000}, {"ltc", 5000}},
|
|
||||||
}
|
|
||||||
cstore := stack.PrefixedStore(coin.NameCoin, store)
|
|
||||||
cstore.Set(otherAddr.Bytes(), wire.BinaryBytes(acct))
|
|
||||||
|
|
||||||
// make proofs for some packets....
|
// make proofs for some packets....
|
||||||
tree := iavl.NewIAVLTree(0, nil)
|
tree := iavl.NewIAVLTree(0, nil)
|
||||||
pbad := Packet{
|
pbad := Packet{
|
||||||
|
|
Loading…
Reference in New Issue