frostfs-contract/tests/proxy_test.go
Evgenii Stratonikov 23e85d11c4
All checks were successful
Tests / Tests (1.19) (pull_request) Successful in 1m27s
DCO action / DCO (pull_request) Successful in 1m36s
Tests / Tests (1.20) (pull_request) Successful in 1m26s
[#53] proxy: Allow using proxy by trusted accounts
It was reverted because `Verify` with arguments was not well supported
by the client software. Thanks to recent `System.Runtime.CurrentSigners`
call from neo-go v0.104.0 we can take the best of both worlds.

Verify with argument still looks better (less overhead), but this
implementation should work too. Sadly, `overloads` are not of much use
here because verification routines take the _first_ method from the
manifest, albeit with arbitrary number of arguments.

This reverts commit a0b73150c6 with some
changes on-top.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-12-15 14:34:26 +03:00

64 lines
2.2 KiB
Go

package tests
import (
"path"
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
const proxyPath = "../proxy"
func deployProxyContract(t *testing.T, e *neotest.Executor, addrNetmap util.Uint160) util.Uint160 {
args := make([]any, 1)
args[0] = addrNetmap
c := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
e.DeployContract(t, c, args)
return c.Hash
}
func newProxyInvoker(t *testing.T) *neotest.ContractInvoker {
e := newExecutor(t)
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"))
ctrProxy := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
deployNetmapContract(t, e, ctrBalance.Hash, ctrContainer.Hash)
deployProxyContract(t, e, ctrNetmap.Hash)
return e.CommitteeInvoker(ctrProxy.Hash)
}
func TestVerify(t *testing.T) {
e := newProxyInvoker(t)
acc := e.NewAccount(t)
gas := e.NewInvoker(e.NativeHash(t, nativenames.Gas), e.Validator)
gas.Invoke(t, true, "transfer", e.Validator.ScriptHash(), e.Hash, 100_0000_0000, nil)
s := neotest.NewContractSigner(e.Hash, func(*transaction.Transaction) []any { return nil })
t.Run("proxy + committee", func(t *testing.T) {
tx := e.PrepareInvocation(t, []byte{byte(opcode.RET)}, []neotest.Signer{s, e.Committee})
require.NoError(t, e.Chain.VerifyTx(tx))
})
t.Run("proxy + custom account", func(t *testing.T) {
t.Run("bad, only proxy", func(t *testing.T) {
tx := e.PrepareInvocation(t, []byte{byte(opcode.RET)}, []neotest.Signer{s, acc})
require.Error(t, e.Chain.VerifyTx(tx))
})
e.Invoke(t, stackitem.Null{}, "addAccount", acc.ScriptHash())
tx := e.PrepareInvocation(t, []byte{byte(opcode.RET)}, []neotest.Signer{s, acc})
require.NoError(t, e.Chain.VerifyTx(tx))
})
}