2021-11-16 14:09:21 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"path"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 11:06:21 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/container"
|
2021-11-16 14:09:21 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-01-11 07:33:14 +00:00
|
|
|
const frostfsidPath = "../frostfsid"
|
2021-11-16 14:09:21 +00:00
|
|
|
|
2023-01-11 07:33:14 +00:00
|
|
|
func deployFrostFSIDContract(t *testing.T, e *neotest.Executor, addrNetmap, addrContainer util.Uint160) util.Uint160 {
|
2023-11-07 11:55:02 +00:00
|
|
|
args := make([]interface{}, 2)
|
|
|
|
args[0] = addrNetmap
|
|
|
|
args[1] = addrContainer
|
2021-11-16 14:09:21 +00:00
|
|
|
|
2023-01-11 07:33:14 +00:00
|
|
|
c := neotest.CompileFile(t, e.CommitteeHash, frostfsidPath, path.Join(frostfsidPath, "config.yml"))
|
2021-11-16 14:09:21 +00:00
|
|
|
e.DeployContract(t, c, args)
|
|
|
|
return c.Hash
|
|
|
|
}
|
|
|
|
|
2023-01-11 07:33:14 +00:00
|
|
|
func newFrostFSIDInvoker(t *testing.T) *neotest.ContractInvoker {
|
2021-11-16 14:09:21 +00:00
|
|
|
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(containerFee),
|
|
|
|
container.AliasFeeKey, int64(containerAliasFee))
|
|
|
|
deployBalanceContract(t, e, ctrNetmap.Hash, ctrContainer.Hash)
|
|
|
|
deployContainerContract(t, e, ctrNetmap.Hash, ctrBalance.Hash, ctrNNS.Hash)
|
2023-01-11 07:33:14 +00:00
|
|
|
h := deployFrostFSIDContract(t, e, ctrNetmap.Hash, ctrContainer.Hash)
|
2021-11-16 14:09:21 +00:00
|
|
|
return e.CommitteeInvoker(h)
|
|
|
|
}
|
|
|
|
|
2023-01-11 07:33:14 +00:00
|
|
|
func TestFrostFSID_AddKey(t *testing.T) {
|
|
|
|
e := newFrostFSIDInvoker(t)
|
2021-11-16 14:09:21 +00:00
|
|
|
|
|
|
|
pubs := make([][]byte, 6)
|
|
|
|
for i := range pubs {
|
|
|
|
p, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
pubs[i] = p.PublicKey().Bytes()
|
|
|
|
}
|
|
|
|
acc := e.NewAccount(t)
|
2023-08-08 08:03:20 +00:00
|
|
|
owner := signerToOwner(acc)
|
2021-11-16 14:09:21 +00:00
|
|
|
e.Invoke(t, stackitem.Null{}, "addKey", owner,
|
|
|
|
[]interface{}{pubs[0], pubs[1]})
|
|
|
|
|
|
|
|
sort.Slice(pubs[:2], func(i, j int) bool {
|
|
|
|
return bytes.Compare(pubs[i], pubs[j]) == -1
|
|
|
|
})
|
|
|
|
arr := []stackitem.Item{
|
|
|
|
stackitem.NewBuffer(pubs[0]),
|
|
|
|
stackitem.NewBuffer(pubs[1]),
|
|
|
|
}
|
|
|
|
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
|
|
|
|
|
|
t.Run("multiple addKey per block", func(t *testing.T) {
|
|
|
|
tx1 := e.PrepareInvoke(t, "addKey", owner, []interface{}{pubs[2]})
|
|
|
|
tx2 := e.PrepareInvoke(t, "addKey", owner, []interface{}{pubs[3], pubs[4]})
|
|
|
|
e.AddNewBlock(t, tx1, tx2)
|
|
|
|
e.CheckHalt(t, tx1.Hash(), stackitem.Null{})
|
|
|
|
e.CheckHalt(t, tx2.Hash(), stackitem.Null{})
|
|
|
|
|
|
|
|
sort.Slice(pubs[:5], func(i, j int) bool {
|
|
|
|
return bytes.Compare(pubs[i], pubs[j]) == -1
|
|
|
|
})
|
|
|
|
arr = []stackitem.Item{
|
|
|
|
stackitem.NewBuffer(pubs[0]),
|
|
|
|
stackitem.NewBuffer(pubs[1]),
|
|
|
|
stackitem.NewBuffer(pubs[2]),
|
|
|
|
stackitem.NewBuffer(pubs[3]),
|
|
|
|
stackitem.NewBuffer(pubs[4]),
|
|
|
|
}
|
|
|
|
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.Invoke(t, stackitem.Null{}, "removeKey", owner,
|
|
|
|
[]interface{}{pubs[1], pubs[5]})
|
|
|
|
arr = []stackitem.Item{
|
|
|
|
stackitem.NewBuffer(pubs[0]),
|
|
|
|
stackitem.NewBuffer(pubs[2]),
|
|
|
|
stackitem.NewBuffer(pubs[3]),
|
|
|
|
stackitem.NewBuffer(pubs[4]),
|
|
|
|
}
|
|
|
|
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
|
|
|
|
|
|
t.Run("multiple removeKey per block", func(t *testing.T) {
|
|
|
|
tx1 := e.PrepareInvoke(t, "removeKey", owner, []interface{}{pubs[2]})
|
|
|
|
tx2 := e.PrepareInvoke(t, "removeKey", owner, []interface{}{pubs[0], pubs[4]})
|
|
|
|
e.AddNewBlock(t, tx1, tx2)
|
|
|
|
e.CheckHalt(t, tx1.Hash(), stackitem.Null{})
|
|
|
|
e.CheckHalt(t, tx2.Hash(), stackitem.Null{})
|
|
|
|
|
|
|
|
arr = []stackitem.Item{stackitem.NewBuffer(pubs[3])}
|
|
|
|
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
|
|
})
|
|
|
|
}
|