2021-10-06 11:59:08 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mr-tron/base58"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
|
|
"github.com/nspcc-dev/neofs-contract/nns"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
const containerPath = "../container"
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
const containerFee = 0_0100_0000
|
|
|
|
|
2021-10-06 11:59:08 +00:00
|
|
|
func deployContainerContract(t *testing.T, bc *core.Blockchain, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 {
|
|
|
|
args := make([]interface{}, 6)
|
|
|
|
args[0] = int64(0)
|
|
|
|
args[1] = addrNetmap
|
|
|
|
args[2] = addrBalance
|
|
|
|
args[3] = util.Uint160{} // not needed for now
|
|
|
|
args[4] = addrNNS
|
|
|
|
args[5] = "neofs"
|
|
|
|
return DeployContract(t, bc, containerPath, args)
|
|
|
|
}
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
func prepareContainerContract(t *testing.T, bc *core.Blockchain) (util.Uint160, util.Uint160) {
|
2021-10-06 11:59:08 +00:00
|
|
|
addrNNS := DeployContract(t, bc, nnsPath, nil)
|
|
|
|
|
|
|
|
ctrNetmap, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), netmapPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ctrBalance, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), balancePath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ctrContainer, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), containerPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
deployNetmapContract(t, bc, ctrBalance.Hash, ctrContainer.Hash, "ContainerFee", int64(containerFee))
|
|
|
|
balHash := deployBalanceContract(t, bc, ctrNetmap.Hash, ctrContainer.Hash)
|
|
|
|
return deployContainerContract(t, bc, ctrNetmap.Hash, ctrBalance.Hash, addrNNS), balHash
|
2021-10-06 11:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setContainerOwner(c []byte, owner *wallet.Account) {
|
|
|
|
copy(c[7:], owner.Contract.ScriptHash().BytesBE())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContainerPut(t *testing.T) {
|
|
|
|
bc := NewChain(t)
|
2021-10-18 11:12:26 +00:00
|
|
|
h, balanceHash := prepareContainerContract(t, bc)
|
2021-10-06 11:59:08 +00:00
|
|
|
|
|
|
|
acc := NewAccount(t, bc)
|
|
|
|
dummySig := make([]byte, 64)
|
|
|
|
dummyPub := make([]byte, 33)
|
|
|
|
dummyToken := make([]byte, 100)
|
|
|
|
container := make([]byte, 100)
|
|
|
|
setContainerOwner(container, acc)
|
|
|
|
containerID := sha256.Sum256(container)
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
putArgs := []interface{}{container, dummySig, dummyPub, dummyToken}
|
|
|
|
tx := PrepareInvoke(t, bc, CommitteeAcc, h, "put", putArgs...)
|
|
|
|
AddBlock(t, bc, tx)
|
|
|
|
CheckFault(t, bc, tx.Hash(), "insufficient balance to create container")
|
|
|
|
|
|
|
|
balanceMint(t, bc, acc, balanceHash, containerFee*1, []byte{})
|
|
|
|
|
|
|
|
tx = PrepareInvoke(t, bc, acc, h, "put", putArgs...)
|
|
|
|
AddBlock(t, bc, tx)
|
|
|
|
CheckFault(t, bc, tx.Hash(), "alphabet witness check failed")
|
|
|
|
|
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, h, "put", putArgs...)
|
2021-10-06 11:59:08 +00:00
|
|
|
AddBlockCheckHalt(t, bc, tx)
|
|
|
|
|
|
|
|
t.Run("with nice names", func(t *testing.T) {
|
|
|
|
nnsHash := contracts[nnsPath].Hash
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
balanceMint(t, bc, acc, balanceHash, containerFee*1, []byte{})
|
|
|
|
|
|
|
|
putArgs := []interface{}{container, dummySig, dummyPub, dummyToken, "mycnt", ""}
|
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, h, "putNamed", putArgs...)
|
2021-10-06 11:59:08 +00:00
|
|
|
AddBlockCheckHalt(t, bc, tx)
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
tx = PrepareInvoke(t, bc, acc, nnsHash, "resolve", "mycnt.neofs", int64(nns.TXT))
|
2021-10-06 11:59:08 +00:00
|
|
|
CheckTestInvoke(t, bc, tx, stackitem.NewArray([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray([]byte(base58.Encode(containerID[:]))),
|
|
|
|
}))
|
|
|
|
|
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, h, "delete", containerID[:], dummySig, dummyToken)
|
|
|
|
AddBlockCheckHalt(t, bc, tx)
|
|
|
|
|
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, nnsHash, "resolve", "mycnt.neofs", int64(nns.TXT))
|
|
|
|
CheckTestInvoke(t, bc, tx, stackitem.Null{})
|
|
|
|
|
|
|
|
t.Run("register in advance", func(t *testing.T) {
|
|
|
|
container[len(container)-1] = 10
|
|
|
|
containerID = sha256.Sum256(container)
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, nnsHash, "register",
|
|
|
|
"second.neofs", CommitteeAcc.Contract.ScriptHash(),
|
2021-10-06 11:59:08 +00:00
|
|
|
"whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0))
|
|
|
|
AddBlockCheckHalt(t, bc, tx)
|
|
|
|
|
2021-10-18 11:12:26 +00:00
|
|
|
balanceMint(t, bc, acc, balanceHash, containerFee*1, []byte{})
|
|
|
|
|
|
|
|
putArgs := []interface{}{container, dummySig, dummyPub, dummyToken, "second", "neofs"}
|
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, h, "putNamed", putArgs...)
|
2021-10-06 11:59:08 +00:00
|
|
|
AddBlockCheckHalt(t, bc, tx)
|
|
|
|
|
|
|
|
tx = PrepareInvoke(t, bc, CommitteeAcc, nnsHash, "resolve", "second.neofs", int64(nns.TXT))
|
|
|
|
CheckTestInvoke(t, bc, tx, stackitem.NewArray([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray([]byte(base58.Encode(containerID[:]))),
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|