frostfs-contract/tests/proxy_test.go
Evgenii Stratonikov 60e8abbf49 [#74] tests: Actualize proxy contract deploy parameters
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-01-29 14:02:18 +03:00

56 lines
1.8 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) util.Uint160 {
c := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
e.DeployContract(t, c, []any{})
return c.Hash
}
func newProxyInvoker(t *testing.T) *neotest.ContractInvoker {
e := newExecutor(t)
ctrProxy := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
deployProxyContract(t, e)
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))
})
}