Skip to content

Commit

Permalink
test: Fix cluster test testOffledgerRequest900KB
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Sep 9, 2023
1 parent 1eaa00f commit f3865f5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
25 changes: 25 additions & 0 deletions packages/vm/core/testcore/blob_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testcore

import (
"crypto/rand"
"fmt"
"testing"

Expand All @@ -12,6 +13,7 @@ import (
"github.com/iotaledger/wasp/packages/kv/codec"
"github.com/iotaledger/wasp/packages/solo"
"github.com/iotaledger/wasp/packages/vm/core/blob"
"github.com/iotaledger/wasp/packages/vm/gas"
)

const (
Expand All @@ -32,6 +34,29 @@ func TestUploadBlob(t *testing.T) {
_, ok := ch.GetBlobInfo(h)
require.True(t, ok)
})
t.Run("huge", func(t *testing.T) {
env := solo.New(t)
ch := env.NewChain()

err := ch.DepositBaseTokensToL2(1_000_000, nil)
require.NoError(t, err)

limits := *gas.LimitsDefault
limits.MaxGasPerRequest = 10 * limits.MaxGasPerRequest
limits.MaxGasExternalViewCall = 10 * limits.MaxGasExternalViewCall
ch.SetGasLimits(nil, &limits)
ch.WaitForRequestsMark()

size := int64(1 * 900 * 1024) // 900 KB
randomData := make([]byte, size+1)
_, err = rand.Read(randomData)
require.NoError(t, err)
h, err := ch.UploadBlob(nil, "field", randomData)
require.NoError(t, err)

_, ok := ch.GetBlobInfo(h)
require.True(t, ok)
})
t.Run("from file", func(t *testing.T) {
env := solo.New(t)
ch := env.NewChain()
Expand Down
42 changes: 39 additions & 3 deletions tools/cluster/tests/offledger_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/iotaledger/wasp/packages/kv/dict"
"github.com/iotaledger/wasp/packages/vm/core/accounts"
"github.com/iotaledger/wasp/packages/vm/core/blob"
"github.com/iotaledger/wasp/packages/vm/core/governance"
"github.com/iotaledger/wasp/packages/vm/gas"
)

func TestOffledgerRequestAccessNode(t *testing.T) {
Expand Down Expand Up @@ -107,15 +109,49 @@ func testOffledgerRequest900KB(t *testing.T, e *ChainEnv) {
paramsDict := dict.Dict{"data": randomData}
expectedHash := blob.MustGetBlobHash(paramsDict)

// raise gas limits, gas cost for 900KB has exceeded the limits
{
limits1 := *gas.LimitsDefault
limits1.MaxGasPerRequest = 10 * limits1.MaxGasPerRequest
limits1.MaxGasExternalViewCall = 10 * limits1.MaxGasExternalViewCall
govClient := e.Chain.SCClient(governance.Contract.Hname(), e.Chain.OriginatorKeyPair)
gasLimitsReq, err1 := govClient.PostOffLedgerRequest(
governance.FuncSetGasLimits.Name,
chainclient.PostRequestParams{
Args: dict.Dict{
governance.ParamGasLimitsBytes: limits1.Bytes(),
},
},
)
require.NoError(t, err1)
_, _, err = e.Clu.WaspClient(0).ChainsApi.
WaitForRequest(context.Background(), e.Chain.ChainID.String(), gasLimitsReq.ID().String()).
TimeoutSeconds(10).
Execute()
require.NoError(t, err)

retDict, err1 := govClient.CallView(context.Background(),
governance.ViewGetGasLimits.Name,
dict.Dict{},
)
require.NoError(t, err1)
limits2, err1 := gas.LimitsFromBytes(retDict.Get(governance.ParamGasLimitsBytes))
require.Equal(t, limits1, *limits2)
require.NoError(t, err1)
}

offledgerReq, err := chClient.PostOffLedgerRequest(context.Background(),
blob.Contract.Hname(),
blob.FuncStoreBlob.Hname(),
chainclient.PostRequestParams{
Args: paramsDict,
})
Args: paramsDict,
Allowance: isc.NewAssetsBaseTokens(10 * isc.Million),
},
)
require.NoError(t, err)

_, err = e.Chain.CommitteeMultiClient().WaitUntilRequestProcessedSuccessfully(e.Chain.ChainID, offledgerReq.ID(), false, 30*time.Second)
_, err = e.Chain.CommitteeMultiClient().
WaitUntilRequestProcessedSuccessfully(e.Chain.ChainID, offledgerReq.ID(), false, 30*time.Second)
require.NoError(t, err)

// ensure blob was stored by the cluster
Expand Down

0 comments on commit f3865f5

Please sign in to comment.