Add test failure (cannot create duplicate)

This commit is contained in:
Ethan Frey 2020-03-12 15:21:16 +01:00
parent e44cce6c8f
commit b389b75fdb
1 changed files with 31 additions and 0 deletions

View File

@ -48,6 +48,37 @@ func TestCreate(t *testing.T) {
require.Equal(t, wasmCode, storedCode)
}
func TestCreateDuplicate(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
ctx, accKeeper, keeper := CreateTestInput(t, false, tempDir)
deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
creator := createFakeFundedAccount(ctx, accKeeper, deposit)
wasmCode, err := ioutil.ReadFile("./testdata/contract.wasm")
require.NoError(t, err)
// create one copy
contractID, err := keeper.Create(ctx, creator, wasmCode, "https://github.com/cosmwasm/wasmd/blob/master/x/wasm/testdata/escrow.wasm", "cosmwasm-opt:0.5.2")
require.NoError(t, err)
require.Equal(t, uint64(1), contractID)
// create second copy
duplicateID, err := keeper.Create(ctx, creator, wasmCode, "https://github.com/cosmwasm/wasmd/blob/master/x/wasm/testdata/escrow.wasm", "cosmwasm-opt:0.5.2")
require.NoError(t, err)
require.Equal(t, uint64(2), duplicateID)
// and verify both content is proper
storedCode, err := keeper.GetByteCode(ctx, contractID)
require.NoError(t, err)
require.Equal(t, wasmCode, storedCode)
storedCode, err = keeper.GetByteCode(ctx, duplicateID)
require.NoError(t, err)
require.Equal(t, wasmCode, storedCode)
}
func TestCreateWithSimulation(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)