2021-12-03 11:17:37 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
2023-12-15 10:50:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2021-12-03 11:17:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2023-12-15 10:50:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
2021-12-03 11:17:37 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2023-12-15 10:50:01 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-12-03 11:17:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const proxyPath = "../proxy"
|
|
|
|
|
2024-01-29 10:34:38 +00:00
|
|
|
func deployProxyContract(t *testing.T, e *neotest.Executor) util.Uint160 {
|
2021-12-03 11:17:37 +00:00
|
|
|
c := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
|
2024-01-29 10:34:38 +00:00
|
|
|
e.DeployContract(t, c, []any{})
|
2021-12-03 11:17:37 +00:00
|
|
|
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"))
|
2024-01-29 10:34:38 +00:00
|
|
|
deployProxyContract(t, e)
|
2021-12-03 11:17:37 +00:00
|
|
|
|
|
|
|
return e.CommitteeInvoker(ctrProxy.Hash)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVerify(t *testing.T) {
|
|
|
|
e := newProxyInvoker(t)
|
2023-12-15 10:50:01 +00:00
|
|
|
acc := e.NewAccount(t)
|
2021-12-03 11:17:37 +00:00
|
|
|
|
2023-12-15 10:50:01 +00:00
|
|
|
gas := e.NewInvoker(e.NativeHash(t, nativenames.Gas), e.Validator)
|
|
|
|
gas.Invoke(t, true, "transfer", e.Validator.ScriptHash(), e.Hash, 100_0000_0000, nil)
|
2021-12-03 11:17:37 +00:00
|
|
|
|
2023-12-15 10:50:01 +00:00
|
|
|
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))
|
|
|
|
})
|
2021-12-03 11:17:37 +00:00
|
|
|
|
2023-12-15 10:50:01 +00:00
|
|
|
e.Invoke(t, stackitem.Null{}, "addAccount", acc.ScriptHash())
|
2021-12-03 11:17:37 +00:00
|
|
|
|
2023-12-15 10:50:01 +00:00
|
|
|
tx := e.PrepareInvocation(t, []byte{byte(opcode.RET)}, []neotest.Signer{s, acc})
|
|
|
|
require.NoError(t, e.Chain.VerifyTx(tx))
|
|
|
|
})
|
2021-12-03 11:17:37 +00:00
|
|
|
}
|