Fix client checksum verification (#1234)
* Fix client checksum verification * Review comments
This commit is contained in:
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user