Skip to content

Commit

Permalink
tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Dec 20, 2024
1 parent 197ee75 commit 9a593c0
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 56 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ linters:
- goimports
- errcheck
- testifylint
- revive

linters-settings:
goimports:
Expand Down
10 changes: 5 additions & 5 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestIBCHandshake(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, i.Ok)
iResponse := i.Ok
require.Equal(t, 0, len(iResponse.Messages))
require.Empty(t, iResponse.Messages)

// channel open
gasMeter2 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
Expand All @@ -132,7 +132,7 @@ func TestIBCHandshake(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, conn.Ok)
connResponse := conn.Ok
require.Equal(t, 1, len(connResponse.Messages))
require.Len(t, connResponse.Messages, 1)

// check for the expected custom event
expected_events := []types.Event{{
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestIBCPacketDispatch(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, conn.Ok)
connResponse := conn.Ok
require.Equal(t, 1, len(connResponse.Messages))
require.Len(t, connResponse.Messages, 1)
id := connResponse.Messages[0].ID

// mock reflect init callback (to store address)
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestIBCPacketDispatch(t *testing.T) {
var accounts ListAccountsResponse
err = json.Unmarshal(qResponse, &accounts)
require.NoError(t, err)
require.Equal(t, 1, len(accounts.Accounts))
require.Len(t, accounts.Accounts, 1)
require.Equal(t, CHANNEL_ID, accounts.Accounts[0].ChannelID)
require.Equal(t, REFLECT_ADDR, accounts.Accounts[0].Account)

Expand Down Expand Up @@ -332,7 +332,7 @@ func TestIBCMsgGetChannel(t *testing.T) {
require.Equal(t, msg1.GetChannel(), msg4.GetChannel())
require.Equal(t, msg1.GetChannel(), msg5.GetChannel())
require.Equal(t, msg1.GetChannel(), msg6.GetChannel())
require.Equal(t, msg1.GetChannel().Endpoint.ChannelID, CHANNEL_ID)
require.Equal(t, CHANNEL_ID, msg1.GetChannel().Endpoint.ChannelID)
}

func TestIBCMsgGetCounterVersion(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions internal/api/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ func TestQueueIteratorSimple(t *testing.T) {
err = json.Unmarshal(data, &reduced)
require.NoError(t, err)
require.Equal(t, "", reduced.Err)
require.Equal(t, `{"counters":[[17,22],[22,0]]}`, string(reduced.Ok))
require.JSONEq(t, `{"counters":[[17,22],[22,0]]}`, string(reduced.Ok))
}

func TestQueueIteratorRaces(t *testing.T) {
cache, _ := withCache(t) // No need for t.Cleanup(cleanup)

assert.Equal(t, 0, len(iteratorFrames))
assert.Empty(t, iteratorFrames)

contract1 := setupQueueContractWithData(t, cache, 17, 22)
contract2 := setupQueueContractWithData(t, cache, 1, 19, 6, 35, 8)
Expand All @@ -234,12 +234,12 @@ func TestQueueIteratorRaces(t *testing.T) {

query := []byte(`{"reducer":{}}`)
data, _, err := Query(cache, checksum, env, query, &igasMeter, store, api, &querier, testingGasLimit, testingPrintDebug)
require.NoError(t, err)
assert.NoError(t, err)
var reduced types.QueryResult
err = json.Unmarshal(data, &reduced)
require.NoError(t, err)
require.Equal(t, "", reduced.Err)
require.Equal(t, fmt.Sprintf(`{"counters":%s}`, expected), string(reduced.Ok))
assert.NoError(t, err)
assert.Equal(t, "", reduced.Err)
assert.Equal(t, fmt.Sprintf(`{"counters":%s}`, expected), string(reduced.Ok))
}

// 30 concurrent batches to trigger race conditions if any
Expand All @@ -264,7 +264,7 @@ func TestQueueIteratorRaces(t *testing.T) {
wg.Wait()

// after all done, no frames should remain
assert.Equal(t, 0, len(iteratorFrames))
assert.Empty(t, iteratorFrames)
}

func TestQueueIteratorLimit(t *testing.T) {
Expand Down
39 changes: 28 additions & 11 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,17 @@ func TestExecute(t *testing.T) {
err = json.Unmarshal(res, &result)
require.NoError(t, err)
require.Equal(t, "", result.Err)
require.Equal(t, 1, len(result.Ok.Messages))
require.Len(t, result.Ok.Messages, 1)
ev := result.Ok.Events[0]
assert.Equal(t, "hackatom", ev.Type)
assert.Equal(t, 1, len(ev.Attributes))
assert.Len(t, ev.Attributes, 1)
assert.Equal(t, "action", ev.Attributes[0].Key)
assert.Equal(t, "release", ev.Attributes[0].Value)

dispatch := result.Ok.Messages[0].Msg
require.NotNil(t, dispatch.Bank)
require.NotNil(t, dispatch.Bank.Send)
send := dispatch.Bank.Send
cosmosMsg := result.Ok.Messages[0].Msg
require.NotNil(t, cosmosMsg.Bank)
require.NotNil(t, cosmosMsg.Bank.Send)
send := cosmosMsg.Bank.Send
assert.Equal(t, "bob", send.ToAddress)
assert.Equal(t, balance, send.Amount)
expectedData := []byte{0xF0, 0x0B, 0xAA}
Expand Down Expand Up @@ -702,8 +702,8 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) {
info = MockInfoBin(b, "fred")

Check failure on line 702 in internal/api/lib_test.go

View workflow job for this annotation

GitHub Actions / lint

go-require: MockInfoBin contains assertions that must only be used in the goroutine running the test function (testifylint)
msg := []byte(`{"allocate_large_memory":{"pages":0}}`)
res, _, err = Execute(cache, checksum, env, info, msg, &igasMeter2, store, api, &querier, testingGasLimit, testingPrintDebug)
require.NoError(b, err)
requireOkResponse(b, res, 0)
assert.NoError(b, err)
assertOkResponse(b, res, 0)
wg.Done()
}()
}
Expand Down Expand Up @@ -765,7 +765,7 @@ func TestMigrate(t *testing.T) {
err = json.Unmarshal(data, &qResult)
require.NoError(t, err)
require.Equal(t, "", qResult.Err)
require.Equal(t, `{"verifier":"fred"}`, string(qResult.Ok))
require.JSONEq(t, `{"verifier":"fred"}`, string(qResult.Ok))

_, _, err = Migrate(cache, checksum, env, []byte(`{"verifier":"alice"}`), &igasMeter, store, api, &querier, testingGasLimit, testingPrintDebug)
require.NoError(t, err)
Expand All @@ -776,7 +776,7 @@ func TestMigrate(t *testing.T) {
err = json.Unmarshal(data, &qResult2)
require.NoError(t, err)
require.Equal(t, "", qResult2.Err)
require.Equal(t, `{"verifier":"alice"}`, string(qResult2.Ok))
require.JSONEq(t, `{"verifier":"alice"}`, string(qResult2.Ok))
}

func TestMultipleInstances(t *testing.T) {
Expand Down Expand Up @@ -994,6 +994,14 @@ func requireOkResponse(t testing.TB, res []byte, expectedMsgs int) {
require.Equal(t, expectedMsgs, len(result.Ok.Messages))
}

func assertOkResponse(t testing.TB, res []byte, expectedMsgs int) {
var result types.ContractResult
err := json.Unmarshal(res, &result)
assert.NoError(t, err)
assert.Equal(t, "", result.Err)
assert.Equal(t, expectedMsgs, len(result.Ok.Messages))

Check failure on line 1002 in internal/api/lib_test.go

View workflow job for this annotation

GitHub Actions / lint

len: use assert.Len (testifylint)
}

func requireQueryError(t *testing.T, res []byte) {
var result types.QueryResult
err := json.Unmarshal(res, &result)
Expand Down Expand Up @@ -1094,7 +1102,7 @@ func TestQuery(t *testing.T) {
err = json.Unmarshal(data, &qResult)
require.NoError(t, err)
require.Equal(t, "", qResult.Err)
require.Equal(t, `{"verifier":"fred"}`, string(qResult.Ok))
require.JSONEq(t, `{"verifier":"fred"}`, string(qResult.Ok))
}

func TestHackatomQuerier(t *testing.T) {
Expand Down Expand Up @@ -1256,3 +1264,12 @@ func TestFloats(t *testing.T) {
hash := hasher.Sum(nil)
require.Equal(t, "95f70fa6451176ab04a9594417a047a1e4d8e2ff809609b8f81099496bee2393", hex.EncodeToString(hash))
}

func MockInfoBinNoAssert(t testing.TB, sender string) []byte {
info := MockInfo(sender, nil)
bin, err := json.Marshal(info)
if err != nil {
t.Fatal(err)
}
return bin
}
6 changes: 3 additions & 3 deletions internal/api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func TestMockApi(t *testing.T) {
human := "foobar"
canon, cost, err := MockCanonicalizeAddress(human)
require.NoError(t, err)
assert.Equal(t, CanonicalLength, len(canon))
assert.Len(t, canon, CanonicalLength)
assert.Equal(t, CostCanonical, cost)

recover, cost, err := MockHumanizeAddress(canon)
Expand Down Expand Up @@ -639,7 +639,7 @@ func TestReflectCustomQuerier(t *testing.T) {
var resp CustomResponse
err = json.Unmarshal(bz, &resp)
require.NoError(t, err)
assert.Equal(t, resp.Msg, "PONG")
assert.Equal(t, "PONG", resp.Msg)

// try capital
msg2, err := json.Marshal(CustomQuery{Capitalized: &CapitalizedQuery{Text: "small."}})
Expand All @@ -649,5 +649,5 @@ func TestReflectCustomQuerier(t *testing.T) {
var resp2 CustomResponse
err = json.Unmarshal(bz, &resp2)
require.NoError(t, err)
assert.Equal(t, resp2.Msg, "SMALL.")
assert.Equal(t, "SMALL.", resp2.Msg)
}
3 changes: 1 addition & 2 deletions internal/api/version_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"regexp"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -10,5 +9,5 @@ import (
func TestLibwasmvmVersion(t *testing.T) {
version, err := LibwasmvmVersion()
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-z0-9.]+)?$`), version)
require.Regexp(t, `^([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-z0-9.]+)?$`, version)
}
14 changes: 7 additions & 7 deletions lib_libwasmvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestHappyPath(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, i.Ok)
ires := i.Ok
require.Equal(t, 0, len(ires.Messages))
require.Empty(t, ires.Messages)

// execute
gasMeter2 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
Expand All @@ -198,7 +198,7 @@ func TestHappyPath(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, h.Ok)
hres := h.Ok
require.Equal(t, 1, len(hres.Messages))
require.Len(t, hres.Messages, 1)

// make sure it read the balance properly and we got 250 atoms
dispatch := hres.Messages[0].Msg
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestEnv(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, i.Ok)
ires := i.Ok
require.Equal(t, 0, len(ires.Messages))
require.Empty(t, ires.Messages)

// Execute mirror env without Transaction
env = types.Env{
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestGetMetrics(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, i.Ok)
ires := i.Ok
require.Equal(t, 0, len(ires.Messages))
require.Empty(t, ires.Messages)

// GetMetrics 3
metrics, err = vm.GetMetrics()
Expand All @@ -328,7 +328,7 @@ func TestGetMetrics(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, i.Ok)
ires = i.Ok
require.Equal(t, 0, len(ires.Messages))
require.Empty(t, ires.Messages)

// GetMetrics 4
metrics, err = vm.GetMetrics()
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestGetMetrics(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, i.Ok)
ires = i.Ok
require.Equal(t, 0, len(ires.Messages))
require.Empty(t, ires.Messages)

// GetMetrics 6
metrics, err = vm.GetMetrics()
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestGetMetrics(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, i.Ok)
ires = i.Ok
require.Equal(t, 0, len(ires.Messages))
require.Empty(t, ires.Messages)

// GetMetrics 8
metrics, err = vm.GetMetrics()
Expand Down
10 changes: 5 additions & 5 deletions types/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ func TestBlockInfoSerialization(t *testing.T) {
}
bz, err := json.Marshal(block)
require.NoError(t, err)
assert.Equal(t, `{"height":123,"time":"1578939743987654321","chain_id":"foobar"}`, string(bz))
assert.JSONEq(t, `{"height":123,"time":"1578939743987654321","chain_id":"foobar"}`, string(bz))

block = BlockInfo{
Height: 0,
Time: 0,
ChainID: "",
0,
0,
"",
}
bz, err = json.Marshal(block)
require.NoError(t, err)
assert.Equal(t, `{"height":0,"time":"0","chain_id":""}`, string(bz))
assert.JSONEq(t, `{"height":0,"time":"0","chain_id":""}`, string(bz))
}

func TestBlockInfoDeserialization(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions types/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestIbcTimeoutSerialization(t *testing.T) {
}
bz, err := json.Marshal(timeout)
require.NoError(t, err)
assert.Equal(t, `{"block":{"revision":17,"height":42},"timestamp":"1578939743987654321"}`, string(bz))
assert.JSONEq(t, `{"block":{"revision":17,"height":42},"timestamp":"1578939743987654321"}`, string(bz))

// Null block
timeout = IBCTimeout{
Expand All @@ -28,7 +28,7 @@ func TestIbcTimeoutSerialization(t *testing.T) {
}
bz, err = json.Marshal(timeout)
require.NoError(t, err)
assert.Equal(t, `{"block":null,"timestamp":"1578939743987654321"}`, string(bz))
assert.JSONEq(t, `{"block":null,"timestamp":"1578939743987654321"}`, string(bz))

// Null timestamp
// This should be `"timestamp":null`, but we are lacking this feature: https://github.com/golang/go/issues/37711
Expand All @@ -42,7 +42,7 @@ func TestIbcTimeoutSerialization(t *testing.T) {
}
bz, err = json.Marshal(timeout)
require.NoError(t, err)
assert.Equal(t, `{"block":{"revision":17,"height":42}}`, string(bz))
assert.JSONEq(t, `{"block":{"revision":17,"height":42}}`, string(bz))
}

func TestIbcTimeoutDeserialization(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestWasmMsgInstantiateSerialization(t *testing.T) {

require.Equal(t, "", msg.Instantiate.Admin)
require.Equal(t, uint64(7897), msg.Instantiate.CodeID)
require.Equal(t, []byte(`{"claim":{}}`), msg.Instantiate.Msg)
require.JSONEq(t, `{"claim":{}}`, string(msg.Instantiate.Msg))
require.Equal(t, Array[Coin]{
{"stones", "321"},
}, msg.Instantiate.Funds)
Expand All @@ -46,7 +46,7 @@ func TestWasmMsgInstantiateSerialization(t *testing.T) {

require.Equal(t, "king", msg.Instantiate.Admin)
require.Equal(t, uint64(7897), msg.Instantiate.CodeID)
require.Equal(t, []byte(`{"claim":{}}`), msg.Instantiate.Msg)
require.JSONEq(t, `{"claim":{}}`, string(msg.Instantiate.Msg))
require.Equal(t, Array[Coin]{}, msg.Instantiate.Funds)
require.Equal(t, "my instance", msg.Instantiate.Label)
}
Expand All @@ -67,7 +67,7 @@ func TestWasmMsgInstantiate2Serialization(t *testing.T) {

require.Equal(t, "", msg.Instantiate2.Admin)
require.Equal(t, uint64(7897), msg.Instantiate2.CodeID)
require.Equal(t, []byte(`{"claim":{}}`), msg.Instantiate2.Msg)
require.JSONEq(t, `{"claim":{}}`, string(msg.Instantiate2.Msg))
require.Equal(t, Array[Coin]{
{"stones", "321"},
}, msg.Instantiate2.Funds)
Expand Down
Loading

0 comments on commit 9a593c0

Please sign in to comment.