Skip to content

Commit

Permalink
Including casmwasm fix in this release (#834)
Browse files Browse the repository at this point in the history
* Allow releasing for tags with appended info (#829)

* We need to release for tags like v1.0.0-beta1, which currently doesn't
  work.  This regex change should alow that

Co-authored-by: Tyler Ruppert <{ID}+{username}@users.noreply.github.com>

* Tweak matching string because it's not regex (#830)

Co-authored-by: Tyler Ruppert <{ID}+{username}@users.noreply.github.com>

* Fix decoding of wasm job payload on execution (#833)

* Add a panic to get the stacktrace

* log the payload

* Fix the incorrect decoding of wasm messages

* Linting

---------

Co-authored-by: Tyler Ruppert <{ID}+{username}@users.noreply.github.com>

---------

Co-authored-by: Tyler Ruppert <{ID}+{username}@users.noreply.github.com>
MechanicalTyler and Tyler Ruppert authored May 10, 2023
1 parent a215aae commit 5916f8f
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions x/scheduler/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -207,6 +207,7 @@ func (k Keeper) ScheduleNow(ctx sdk.Context, jobID string, in []byte) error {
"couldn't execute a job",
"job_id", jobID,
"err", err,
"payload", payload,
"chain_type", router.GetChainType(),
"chain_reference_id", router.GetChainReferenceID(),
)
16 changes: 14 additions & 2 deletions x/scheduler/keeper/wasm_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package keeper

import (
"encoding/hex"
"encoding/json"
"fmt"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/VolumeFi/whoops"
@@ -27,10 +29,20 @@ func (e ExecuteJobWasmEvent) valid() error {
return nil
}

func (k Keeper) UnmarshallJob(msg []byte) (ExecuteJobWasmEvent, error) {
var executeMsg ExecuteJobWasmEvent
err := json.Unmarshal(msg, &executeMsg)

hexString := hex.EncodeToString(executeMsg.Payload)

executeMsg.Payload = []byte(fmt.Sprintf("{\"hexPayload\":\"%s\"}", hexString))

return executeMsg, err
}

func (k Keeper) ExecuteWasmJobEventListener() wasmutil.MessengerFnc {
return func(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error) {
var executeMsg ExecuteJobWasmEvent
err := json.Unmarshal(msg.Custom, &executeMsg)
executeMsg, err := k.UnmarshallJob(msg.Custom)
if err != nil {
return nil, nil, err
}
29 changes: 29 additions & 0 deletions x/scheduler/keeper/wasm_handler_test.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package keeper_test

import (
"encoding/json"
"testing"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
@@ -13,6 +14,7 @@ import (
xchainmocks "github.com/palomachain/paloma/internal/x-chain/mocks"
"github.com/palomachain/paloma/x/scheduler/keeper"
"github.com/palomachain/paloma/x/scheduler/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

@@ -105,3 +107,30 @@ var _ = Describe("wasm message handler", func() {
})
})
})

func TestKeeper_UnmarshallJob(t *testing.T) {
tests := []struct {
name string
input []byte
expected keeper.ExecuteJobWasmEvent
expectedError error
}{
{
name: "Happy Path",
input: []byte("{\"job_id\":\"dca_test_job_2\",\"payload\":\"2WBzzwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZmYQoclhTARc=\"}"),
expected: keeper.ExecuteJobWasmEvent{
JobID: "dca_test_job_2",
Payload: []byte("{\"hexPayload\":\"d96073cf00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000199984287258530117\"}"),
},
},
}
asserter := assert.New(t)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
testKeeper := keeper.Keeper{}
actual, _ := testKeeper.UnmarshallJob(tt.input)
asserter.Equal(string(tt.expected.Payload), string(actual.Payload))
})
}
}

0 comments on commit 5916f8f

Please sign in to comment.