Skip to content

Commit

Permalink
fixup! test: Take even more debug additions from #10165
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Nov 7, 2024
1 parent a0c1b06 commit 8c4c670
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
11 changes: 7 additions & 4 deletions golang/cosmos/x/swingset/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type walletSpendAction struct {
type MultiStoreSpy struct {
storetypes.MultiStore
}

func (spy MultiStoreSpy) GetKVStore(storeKey storetypes.StoreKey) storetypes.KVStore {
return KVStoreSpy{spy.MultiStore.GetKVStore(storeKey), storeKey.Name()}
}
Expand All @@ -113,16 +114,17 @@ type KVStoreSpy struct {
storetypes.KVStore
name string
}

func (spy KVStoreSpy) Get(key []byte) []byte {
got := spy.KVStore.Get(key)
stdlog.Printf("xxx gibson KVStore(%#q).Get(%#q) = %#q [k+v = %d]\n",
spy.name, key, got, len(key) + len(got))
spy.name, key, got, len(key)+len(got))
return got
}
func (spy KVStoreSpy) Set(key, value []byte) {
spy.KVStore.Set(key, value)
stdlog.Printf("xxx gibson KVStore(%#q).Set(%#q, %#q) [k+v = %d]\n",
spy.name, key, value, len(key) + len(value))
spy.name, key, value, len(key)+len(value))
}
func (spy KVStoreSpy) Has(key []byte) bool {
found := spy.KVStore.Has(key)
Expand All @@ -139,6 +141,7 @@ func (spy KVStoreSpy) Delete(key []byte) {
type GasMeterSpy struct {
storetypes.GasMeter
}

func (spy GasMeterSpy) ConsumeGas(amount storetypes.Gas, descriptor string) {
stdlog.Printf("xxx gibson ConsumeGas %v %v\n", descriptor, amount)
spy.GasMeter.ConsumeGas(amount, descriptor)
Expand All @@ -159,8 +162,8 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
"remaining": gasMeter.GasRemaining(),
"limit": gasMeter.Limit(),
}
stdlog.Printf("xxx gibson WalletSpendAction GasConfig %+v %v\n",
ctx.KVGasConfig(), meterState)
stdlog.Printf("xxx gibson WalletSpendAction GasConfig %s %+v %v\n",
msg.Owner, ctx.KVGasConfig(), meterState)
ctx = ctx.WithMultiStore(&MultiStoreSpy{ctx.MultiStore()})
ctx = ctx.WithGasMeter(&GasMeterSpy{gasMeter})
}
Expand Down
58 changes: 57 additions & 1 deletion golang/cosmos/x/swingset/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

sdkioerrors "cosmossdk.io/errors"
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -281,6 +282,51 @@ func NewMsgWalletSpendAction(owner sdk.AccAddress, spendAction string) *MsgWalle
}
}

type MultiStoreSpy struct {
storetypes.MultiStore
}

func (spy MultiStoreSpy) GetKVStore(storeKey storetypes.StoreKey) storetypes.KVStore {
return KVStoreSpy{spy.MultiStore.GetKVStore(storeKey), storeKey.Name()}
}

type KVStoreSpy struct {
storetypes.KVStore
name string
}

func (spy KVStoreSpy) Get(key []byte) []byte {
got := spy.KVStore.Get(key)
stdlog.Printf("xxx gibson KVStore(%#q).Get(%#q) = %#q [k+v = %d]\n",
spy.name, key, got, len(key)+len(got))
return got
}
func (spy KVStoreSpy) Set(key, value []byte) {
spy.KVStore.Set(key, value)
stdlog.Printf("xxx gibson KVStore(%#q).Set(%#q, %#q) [k+v = %d]\n",
spy.name, key, value, len(key)+len(value))
}
func (spy KVStoreSpy) Has(key []byte) bool {
found := spy.KVStore.Has(key)
stdlog.Printf("xxx gibson KVStore(%#q).Has(%#q) = %v\n",
spy.name, key, found)
return found
}
func (spy KVStoreSpy) Delete(key []byte) {
spy.KVStore.Delete(key)
stdlog.Printf("xxx gibson KVStore(%#q).Delete(%#q)\n",
spy.name, key)
}

type GasMeterSpy struct {
storetypes.GasMeter
}

func (spy GasMeterSpy) ConsumeGas(amount storetypes.Gas, descriptor string) {
stdlog.Printf("xxx gibson ConsumeGas %v %v\n", descriptor, amount)
spy.GasMeter.ConsumeGas(amount, descriptor)
}

// CheckAdmissibility implements the vm.ControllerAdmissionMsg interface.
func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interface{}) error {
xxx_gibson := false
Expand All @@ -289,7 +335,17 @@ func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interfa
xxx_gibson = xxx_gibson || ok && key == "XXX_GIBSON" && value != "" && value != "0"
}
if xxx_gibson {
stdlog.Println("xxx gibson WalletSpendAction.CheckAdmissibility", msg.Owner)
gasMeter := ctx.GasMeter()
meterState := map[string]storetypes.Gas{
"consumed": gasMeter.GasConsumed(),
"consumedToLimit": gasMeter.GasConsumedToLimit(),
"remaining": gasMeter.GasRemaining(),
"limit": gasMeter.Limit(),
}
stdlog.Printf("xxx gibson WalletSpendAction.CheckAdmissibility GasConfig %s %+v %v\n",
msg.Owner, ctx.KVGasConfig(), meterState)
ctx = ctx.WithMultiStore(&MultiStoreSpy{ctx.MultiStore()})
ctx = ctx.WithGasMeter(&GasMeterSpy{gasMeter})
}
keeper, ok := data.(SwingSetKeeper)
if !ok {
Expand Down

0 comments on commit 8c4c670

Please sign in to comment.