From 184fcdc5a76e3a948aec82362023b386aba7be9b Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 24 Oct 2023 13:16:47 +0300 Subject: [PATCH] [#45] container: Add test of inconsistent container creation fee Signed-off-by: Alex Vanin --- tests/container_test.go | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/container_test.go b/tests/container_test.go index 0508c3c..5c115c3 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -3,6 +3,7 @@ package tests import ( "bytes" "crypto/sha256" + "fmt" "math/big" "path" "testing" @@ -12,6 +13,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-contract/nns" "github.com/mr-tron/base58" "github.com/nspcc-dev/neo-go/pkg/core/interop/storage" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/util" @@ -57,6 +59,24 @@ func newContainerInvoker(t *testing.T) (*neotest.ContractInvoker, *neotest.Contr return e.CommitteeInvoker(ctrContainer.Hash), e.CommitteeInvoker(ctrBalance.Hash), e.CommitteeInvoker(ctrNetmap.Hash) } +// TODO(alexvanin): remove this after fix of inconsistent tx cost in balance contract +func newFreeContainerInvoker(t *testing.T) (*neotest.ContractInvoker, *neotest.ContractInvoker, *neotest.ContractInvoker) { + e := newExecutor(t) + + ctrNNS := neotest.CompileFile(t, e.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml")) + ctrNetmap := neotest.CompileFile(t, e.CommitteeHash, netmapPath, path.Join(netmapPath, "config.yml")) + ctrBalance := neotest.CompileFile(t, e.CommitteeHash, balancePath, path.Join(balancePath, "config.yml")) + ctrContainer := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml")) + + e.DeployContract(t, ctrNNS, nil) + deployNetmapContract(t, e, ctrBalance.Hash, ctrContainer.Hash, + container.RegistrationFeeKey, int64(0), + container.AliasFeeKey, int64(0)) + deployBalanceContract(t, e, ctrNetmap.Hash, ctrContainer.Hash) + deployContainerContract(t, e, ctrNetmap.Hash, ctrBalance.Hash, ctrNNS.Hash) + return e.CommitteeInvoker(ctrContainer.Hash), e.CommitteeInvoker(ctrBalance.Hash), e.CommitteeInvoker(ctrNetmap.Hash) +} + func setContainerOwner(c []byte, acc neotest.Signer) { copy(c[6:], signerToOwner(acc)) } @@ -231,6 +251,30 @@ func TestContainerPut(t *testing.T) { cNNS.Invoke(t, expected, "resolve", "domain.cdn", int64(nns.TXT)) }) }) + + t.Run("gas costs are the same for all containers in block", func(t *testing.T) { + c, _, _ := newFreeContainerInvoker(t) + const containerPerBlock = 512 + + acc := c.NewAccount(t) + cnt := dummyContainer(acc) + putArgs := []interface{}{cnt.value, cnt.sig, cnt.pub, cnt.token, "precreated", ""} + c.Invoke(t, stackitem.Null{}, "putNamed", putArgs...) + + txs := make([]*transaction.Transaction, 0, containerPerBlock) + for i := 0; i < containerPerBlock; i++ { + cnt := dummyContainer(acc) + name := fmt.Sprintf("name-%.5d", i) + tx := c.PrepareInvoke(t, "putNamed", cnt.value, cnt.sig, cnt.pub, cnt.token, name, "") + txs = append(txs, tx) + } + + c.AddNewBlock(t, txs...) + + for i := 0; i < containerPerBlock; i++ { + c.CheckHalt(t, txs[i].Hash(), stackitem.Make(stackitem.Null{})) + } + }) } func addContainer(t *testing.T, c, cBal *neotest.ContractInvoker) (neotest.Signer, testContainer) {