Fix client checksum verification (#1234)

* Fix client checksum verification

* Review comments
This commit is contained in:
Alexander Peters
2023-03-06 14:11:11 +01:00
committed by GitHub
parent cb17a4173f
commit 1a8019b380
5 changed files with 90 additions and 7 deletions

View File

@@ -1,11 +1,14 @@
package cli
import (
"encoding/hex"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/CosmWasm/wasmd/x/wasm/ioutils"
"github.com/CosmWasm/wasmd/x/wasm/types"
)
@@ -57,3 +60,65 @@ func TestParseAccessConfigFlags(t *testing.T) {
})
}
}
func TestParseVerificationFlags(t *testing.T) {
mySender := sdk.MustAccAddressFromBech32("cosmos1wyqh3n50ecatjg4vww5crmtd0nmyzusnwckw4at4gluc0m5m477q4arfek")
specs := map[string]struct {
srcPath string
args []string
expErr bool
expSource string
expBuilder string
expCodeHash string
}{
"gov store zipped": {
srcPath: "../../keeper/testdata/hackatom.wasm.gzip",
args: []string{
"--instantiate-everybody=true", "--code-hash=beb3de5e9b93b52e514c74ce87ccddb594b9bcd33b7f1af1bb6da63fc883917b",
"--code-source-url=https://example.com", "--builder=cosmwasm/workspace-optimizer:0.12.11",
},
expBuilder: "cosmwasm/workspace-optimizer:0.12.11",
expSource: "https://example.com",
expCodeHash: "beb3de5e9b93b52e514c74ce87ccddb594b9bcd33b7f1af1bb6da63fc883917b",
},
"gov store raw": {
srcPath: "../../keeper/testdata/hackatom.wasm",
args: []string{
"--instantiate-everybody=true", "--code-hash=beb3de5e9b93b52e514c74ce87ccddb594b9bcd33b7f1af1bb6da63fc883917b",
"--code-source-url=https://example.com", "--builder=cosmwasm/workspace-optimizer:0.12.11",
},
expBuilder: "cosmwasm/workspace-optimizer:0.12.11",
expSource: "https://example.com",
expCodeHash: "beb3de5e9b93b52e514c74ce87ccddb594b9bcd33b7f1af1bb6da63fc883917b",
},
"gov store checksum mismatch": {
srcPath: "../../keeper/testdata/hackatom.wasm",
args: []string{
"--instantiate-everybody=true", "--code-hash=0000de5e9b93b52e514c74ce87ccddb594b9bcd33b7f1af1bb6da63fc883917b",
"--code-source-url=https://example.com", "--builder=cosmwasm/workspace-optimizer:0.12.11",
},
expErr: true,
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
flagSet := ProposalStoreCodeCmd().Flags()
require.NoError(t, flagSet.Parse(spec.args))
gotMsg, err := parseStoreCodeArgs(spec.srcPath, mySender, flagSet)
require.NoError(t, err)
require.True(t, ioutils.IsGzip(gotMsg.WASMByteCode))
gotSource, gotBuilder, gotCodeHash, gotErr := parseVerificationFlags(gotMsg.WASMByteCode, flagSet)
if spec.expErr {
require.Error(t, gotErr)
return
}
require.NoError(t, gotErr)
assert.Equal(t, spec.expSource, gotSource)
assert.Equal(t, spec.expBuilder, gotBuilder)
assert.Equal(t, spec.expCodeHash, hex.EncodeToString(gotCodeHash))
})
}
}