From c957b9ca696a0aa0803940a289dc0f5c89e71160 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 18 Oct 2021 13:45:10 +0300 Subject: [PATCH] [#151] container: require additional fee for nice-name Signed-off-by: Evgenii Stratonikov --- container/container_contract.go | 6 ++++++ tests/container_test.go | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/container/container_contract.go b/container/container_contract.go index 7458b4b..f477fe7 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -53,6 +53,8 @@ const ( // RegistrationFeeKey is a key in netmap config which contains fee for container registration. RegistrationFeeKey = "ContainerFee" + // AliasFeeKey is a key in netmap config which contains fee for nice-name registration. + AliasFeeKey = "ContainerAliasFee" containerIDSize = 32 // SHA256 size @@ -180,6 +182,10 @@ func PutNamed(container []byte, signature interop.Signature, balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160) containerFee := contract.Call(netmapContractAddr, "config", contract.ReadOnly, RegistrationFeeKey).(int) balance := contract.Call(balanceContractAddr, "balanceOf", contract.ReadOnly, from).(int) + if name != "" { + aliasFee := contract.Call(netmapContractAddr, "config", contract.ReadOnly, AliasFeeKey).(int) + containerFee += aliasFee + } if balance < containerFee*len(alphabet) { panic("insufficient balance to create container") diff --git a/tests/container_test.go b/tests/container_test.go index 0d95bb5..605a8d9 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -16,7 +16,10 @@ import ( const containerPath = "../container" -const containerFee = 0_0100_0000 +const ( + containerFee = 0_0100_0000 + containerAliasFee = 0_0050_0000 +) func deployContainerContract(t *testing.T, bc *core.Blockchain, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 { args := make([]interface{}, 6) @@ -41,7 +44,9 @@ func prepareContainerContract(t *testing.T, bc *core.Blockchain) (util.Uint160, ctrContainer, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), containerPath) require.NoError(t, err) - deployNetmapContract(t, bc, ctrBalance.Hash, ctrContainer.Hash, container.RegistrationFeeKey, int64(containerFee)) + deployNetmapContract(t, bc, ctrBalance.Hash, ctrContainer.Hash, + container.RegistrationFeeKey, int64(containerFee), + container.AliasFeeKey, int64(containerAliasFee)) balHash := deployBalanceContract(t, bc, ctrNetmap.Hash, ctrContainer.Hash) return deployContainerContract(t, bc, ctrNetmap.Hash, ctrBalance.Hash, addrNNS), balHash } @@ -96,6 +101,14 @@ func TestContainerPut(t *testing.T) { balanceMint(t, bc, acc, balanceHash, containerFee*1, []byte{}) putArgs := []interface{}{c.value, c.sig, c.pub, c.token, "mycnt", ""} + t.Run("no fee for alias", func(t *testing.T) { + tx = PrepareInvoke(t, bc, acc, h, "putNamed", putArgs...) + AddBlock(t, bc, tx) + CheckFault(t, bc, tx.Hash(), "insufficient balance to create container") + }) + + balanceMint(t, bc, acc, balanceHash, containerAliasFee*1, []byte{}) + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "putNamed", putArgs...) AddBlockCheckHalt(t, bc, tx) @@ -131,7 +144,7 @@ func TestContainerPut(t *testing.T) { "whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0)) AddBlockCheckHalt(t, bc, tx) - balanceMint(t, bc, acc, balanceHash, containerFee*1, []byte{}) + balanceMint(t, bc, acc, balanceHash, (containerFee+containerAliasFee)*1, []byte{}) putArgs := []interface{}{c.value, c.sig, c.pub, c.token, "second", "neofs"} tx = PrepareInvoke(t, bc, []*wallet.Account{CommitteeAcc, acc}, h, "putNamed", putArgs...)