services: allow multiple listen addresses for simple services

And deprecate the old way of Address/Port configuration for these services.
This commit is contained in:
Anna Shaleva 2022-11-25 13:20:53 +03:00
parent 6b4dd5703e
commit 9087854b1e
33 changed files with 478 additions and 290 deletions

View file

@ -102,3 +102,16 @@ startup to inform about this, it's very easy to deal with this configuration
change, just replace one line. change, just replace one line.
Removal of SecondsPerBlock is scheduled for May-June 2023 (~0.103.0 release). Removal of SecondsPerBlock is scheduled for May-June 2023 (~0.103.0 release).
## Services address and port configuration
Version 0.100.0 of NeoGo introduces a multiple binding addresses capability to
the node's services (RPC server, TLS RPC configuration, Prometheus, Pprof)
that allows to specify several listen addresses/ports using an array of
"address:port" pairs in the service `Addresses` config section. Deprecated
`Address` and `Port` sections of `RPC`, `Prometheus`, `Pprof` subsections of the
`ApplicationConfiguration` as far as the one of RPC server's `TLSConfig` are
still available, but will be removed, so please convert your node configuration
file to use new `Addresses` section for node services.
Removal of these config sections is scheduled for May-June 2023 (~0.103.0 release).

View file

@ -47,7 +47,7 @@ func TestNEP11Import(t *testing.T) {
args := []string{ args := []string{
"neo-go", "wallet", "nep11", "import", "neo-go", "wallet", "nep11", "import",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
} }
// missing token hash // missing token hash
@ -123,7 +123,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// transfer funds to contract owner // transfer funds to contract owner
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--to", nftOwnerAddr, "--to", nftOwnerAddr,
"--token", "GAS", "--token", "GAS",
@ -139,7 +139,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// mint 1 HASHY token by transferring 10 GAS to HASHY contract // mint 1 HASHY token by transferring 10 GAS to HASHY contract
e.In.WriteString(nftOwnerPass + "\r") e.In.WriteString(nftOwnerPass + "\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--to", h.StringLE(), "--to", h.StringLE(),
"--token", "GAS", "--token", "GAS",
@ -166,7 +166,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// check the balance // check the balance
cmdCheckBalance := []string{"neo-go", "wallet", "nep11", "balance", cmdCheckBalance := []string{"neo-go", "wallet", "nep11", "balance",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--address", nftOwnerAddr} "--address", nftOwnerAddr}
checkBalanceResult := func(t *testing.T, acc string, ids ...[]byte) { checkBalanceResult := func(t *testing.T, acc string, ids ...[]byte) {
@ -201,7 +201,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// import token // import token
e.Run(t, "neo-go", "wallet", "nep11", "import", e.Run(t, "neo-go", "wallet", "nep11", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--token", h.StringLE()) "--token", h.StringLE())
@ -211,7 +211,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// balance check: all accounts // balance check: all accounts
e.Run(t, "neo-go", "wallet", "nep11", "balance", e.Run(t, "neo-go", "wallet", "nep11", "balance",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--token", h.StringLE()) "--token", h.StringLE())
checkBalanceResult(t, nftOwnerAddr, tokenID) checkBalanceResult(t, nftOwnerAddr, tokenID)
@ -223,7 +223,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// ownerOf: missing contract hash // ownerOf: missing contract hash
cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOf", cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOf",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdOwnerOf...) e.RunWithError(t, cmdOwnerOf...)
cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE()) cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE())
@ -238,7 +238,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// tokensOf: missing contract hash // tokensOf: missing contract hash
cmdTokensOf := []string{"neo-go", "wallet", "nep11", "tokensOf", cmdTokensOf := []string{"neo-go", "wallet", "nep11", "tokensOf",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdTokensOf...) e.RunWithError(t, cmdTokensOf...)
cmdTokensOf = append(cmdTokensOf, "--token", h.StringLE()) cmdTokensOf = append(cmdTokensOf, "--token", h.StringLE())
@ -254,7 +254,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// properties: no contract // properties: no contract
cmdProperties := []string{ cmdProperties := []string{
"neo-go", "wallet", "nep11", "properties", "neo-go", "wallet", "nep11", "properties",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdProperties...) e.RunWithError(t, cmdProperties...)
cmdProperties = append(cmdProperties, "--token", h.StringLE()) cmdProperties = append(cmdProperties, "--token", h.StringLE())
@ -280,7 +280,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// tokens: missing contract hash // tokens: missing contract hash
cmdTokens := []string{"neo-go", "wallet", "nep11", "tokens", cmdTokens := []string{"neo-go", "wallet", "nep11", "tokens",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdTokens...) e.RunWithError(t, cmdTokens...)
cmdTokens = append(cmdTokens, "--token", h.StringLE()) cmdTokens = append(cmdTokens, "--token", h.StringLE())
@ -298,7 +298,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
cmdTransfer := []string{ cmdTransfer := []string{
"neo-go", "wallet", "nep11", "transfer", "neo-go", "wallet", "nep11", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--to", testcli.ValidatorAddr, "--to", testcli.ValidatorAddr,
"--from", nftOwnerAddr, "--from", nftOwnerAddr,
@ -328,7 +328,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
verifyH := deployVerifyContract(t, e) verifyH := deployVerifyContract(t, e)
cmdTransfer = []string{ cmdTransfer = []string{
"neo-go", "wallet", "nep11", "transfer", "neo-go", "wallet", "nep11", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--to", verifyH.StringLE(), "--to", verifyH.StringLE(),
"--from", nftOwnerAddr, "--from", nftOwnerAddr,
@ -398,7 +398,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// mint 1.00 NFSO token by transferring 10 GAS to NFSO contract // mint 1.00 NFSO token by transferring 10 GAS to NFSO contract
e.In.WriteString(testcli.ValidatorPass + "\r") e.In.WriteString(testcli.ValidatorPass + "\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--to", h.StringLE(), "--to", h.StringLE(),
"--token", "GAS", "--token", "GAS",
@ -432,7 +432,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// check properties // check properties
e.Run(t, "neo-go", "wallet", "nep11", "properties", e.Run(t, "neo-go", "wallet", "nep11", "properties",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--token", h.StringLE(), "--token", h.StringLE(),
"--id", hex.EncodeToString(token1ID)) "--id", hex.EncodeToString(token1ID))
jProps := e.GetNextLine(t) jProps := e.GetNextLine(t)
@ -449,7 +449,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// check the balance // check the balance
cmdCheckBalance := []string{"neo-go", "wallet", "nep11", "balance", cmdCheckBalance := []string{"neo-go", "wallet", "nep11", "balance",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--address", testcli.ValidatorAddr} "--address", testcli.ValidatorAddr}
checkBalanceResult := func(t *testing.T, acc string, objs ...idAmount) { checkBalanceResult := func(t *testing.T, acc string, objs ...idAmount) {
@ -481,7 +481,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// import token // import token
e.Run(t, "neo-go", "wallet", "nep11", "import", e.Run(t, "neo-go", "wallet", "nep11", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--token", h.StringLE()) "--token", h.StringLE())
@ -500,7 +500,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// ownerOfD: missing contract hash // ownerOfD: missing contract hash
cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOfD", cmdOwnerOf := []string{"neo-go", "wallet", "nep11", "ownerOfD",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdOwnerOf...) e.RunWithError(t, cmdOwnerOf...)
cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE()) cmdOwnerOf = append(cmdOwnerOf, "--token", h.StringLE())
@ -515,7 +515,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// tokensOf: missing contract hash // tokensOf: missing contract hash
cmdTokensOf := []string{"neo-go", "wallet", "nep11", "tokensOf", cmdTokensOf := []string{"neo-go", "wallet", "nep11", "tokensOf",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdTokensOf...) e.RunWithError(t, cmdTokensOf...)
cmdTokensOf = append(cmdTokensOf, "--token", h.StringLE()) cmdTokensOf = append(cmdTokensOf, "--token", h.StringLE())
@ -533,7 +533,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// properties: no contract // properties: no contract
cmdProperties := []string{ cmdProperties := []string{
"neo-go", "wallet", "nep11", "properties", "neo-go", "wallet", "nep11", "properties",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdProperties...) e.RunWithError(t, cmdProperties...)
cmdProperties = append(cmdProperties, "--token", h.StringLE()) cmdProperties = append(cmdProperties, "--token", h.StringLE())
@ -566,7 +566,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
// tokens: missing contract hash // tokens: missing contract hash
cmdTokens := []string{"neo-go", "wallet", "nep11", "tokens", cmdTokens := []string{"neo-go", "wallet", "nep11", "tokens",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
} }
e.RunWithError(t, cmdTokens...) e.RunWithError(t, cmdTokens...)
cmdTokens = append(cmdTokens, "--token", h.StringLE()) cmdTokens = append(cmdTokens, "--token", h.StringLE())
@ -582,7 +582,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
cmdTransfer := []string{ cmdTransfer := []string{
"neo-go", "wallet", "nep11", "transfer", "neo-go", "wallet", "nep11", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--to", nftOwnerAddr, "--to", nftOwnerAddr,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
@ -612,7 +612,7 @@ func TestNEP11_D_OwnerOf_BalanceOf_Transfer(t *testing.T) {
verifyH := deployVerifyContract(t, e) verifyH := deployVerifyContract(t, e)
cmdTransfer = []string{ cmdTransfer = []string{
"neo-go", "wallet", "nep11", "transfer", "neo-go", "wallet", "nep11", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", wall, "--wallet", wall,
"--to", verifyH.StringLE(), "--to", verifyH.StringLE(),
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,

View file

@ -21,7 +21,7 @@ func TestNEP17Balance(t *testing.T) {
e := testcli.NewExecutor(t, true) e := testcli.NewExecutor(t, true)
cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"} cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
cmdbase := append(cmdbalance, cmdbase := append(cmdbalance,
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
) )
cmd := append(cmdbase, "--address", testcli.ValidatorAddr) cmd := append(cmdbase, "--address", testcli.ValidatorAddr)
@ -122,7 +122,7 @@ func TestNEP17Transfer(t *testing.T) {
e := testcli.NewExecutor(t, true) e := testcli.NewExecutor(t, true)
args := []string{ args := []string{
"neo-go", "wallet", "nep17", "transfer", "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--to", w.Accounts[0].Address, "--to", w.Accounts[0].Address,
"--token", "NEO", "--token", "NEO",
@ -182,7 +182,7 @@ func TestNEP17Transfer(t *testing.T) {
t.Run("default address", func(t *testing.T) { t.Run("default address", func(t *testing.T) {
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--force", "--force",
@ -208,7 +208,7 @@ func TestNEP17Transfer(t *testing.T) {
t.Run("with signers", func(t *testing.T) { t.Run("with signers", func(t *testing.T) {
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--force", "--force",
@ -221,7 +221,7 @@ func TestNEP17Transfer(t *testing.T) {
validTil := e.Chain.BlockHeight() + 100 validTil := e.Chain.BlockHeight() + 100
cmd := []string{ cmd := []string{
"neo-go", "wallet", "nep17", "transfer", "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--to", address.Uint160ToString(e.Chain.GetNotaryContractScriptHash()), "--to", address.Uint160ToString(e.Chain.GetNotaryContractScriptHash()),
"--token", "GAS", "--token", "GAS",
@ -262,7 +262,7 @@ func TestNEP17MultiTransfer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
args := []string{ args := []string{
"neo-go", "wallet", "nep17", "multitransfer", "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--force", "--force",
@ -318,26 +318,26 @@ func TestNEP17ImportToken(t *testing.T) {
// missing token hash // missing token hash
e.RunWithError(t, "neo-go", "wallet", "nep17", "import", e.RunWithError(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath) "--wallet", walletPath)
// additional parameter // additional parameter
e.RunWithError(t, "neo-go", "wallet", "nep17", "import", e.RunWithError(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
"--token", gasContractHash.StringLE(), "useless") "--token", gasContractHash.StringLE(), "useless")
e.Run(t, "neo-go", "wallet", "nep17", "import", e.Run(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
"--token", gasContractHash.StringLE()) "--token", gasContractHash.StringLE())
e.Run(t, "neo-go", "wallet", "nep17", "import", e.Run(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
"--token", address.Uint160ToString(neoContractHash)) // try address instead of sh "--token", address.Uint160ToString(neoContractHash)) // try address instead of sh
// not a NEP-17 token // not a NEP-17 token
e.RunWithError(t, "neo-go", "wallet", "nep17", "import", e.RunWithError(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
"--token", nnsContractHash.StringLE()) "--token", nnsContractHash.StringLE())

View file

@ -24,7 +24,7 @@ func TestGetRPCClient(t *testing.T) {
t.Run("success", func(t *testing.T) { t.Run("success", func(t *testing.T) {
set := flag.NewFlagSet("flagSet", flag.ExitOnError) set := flag.NewFlagSet("flagSet", flag.ExitOnError)
set.String(options.RPCEndpointFlag, "http://"+e.RPC.Addr, "") set.String(options.RPCEndpointFlag, "http://"+e.RPC.Addresses()[0], "")
ctx := cli.NewContext(app.New(), set, nil) ctx := cli.NewContext(app.New(), set, nil)
gctx, _ := options.GetTimeoutContext(ctx) gctx, _ := options.GetTimeoutContext(ctx)
_, ec := options.GetRPCClient(gctx, ctx) _, ec := options.GetRPCClient(gctx, ctx)

View file

@ -30,7 +30,7 @@ func TestQueryTx(t *testing.T) {
transferArgs := []string{ transferArgs := []string{
"neo-go", "wallet", "nep17", "transfer", "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--to", w.Accounts[0].Address, "--to", w.Accounts[0].Address,
"--token", "NEO", "--token", "NEO",
@ -47,7 +47,7 @@ func TestQueryTx(t *testing.T) {
tx, ok := e.Chain.GetMemPool().TryGetValue(txHash) tx, ok := e.Chain.GetMemPool().TryGetValue(txHash)
require.True(t, ok) require.True(t, ok)
args := []string{"neo-go", "query", "tx", "--rpc-endpoint", "http://" + e.RPC.Addr} args := []string{"neo-go", "query", "tx", "--rpc-endpoint", "http://" + e.RPC.Addresses()[0]}
e.Run(t, append(args, txHash.StringLE())...) e.Run(t, append(args, txHash.StringLE())...)
e.CheckNextLine(t, `Hash:\s+`+txHash.StringLE()) e.CheckNextLine(t, `Hash:\s+`+txHash.StringLE())
e.CheckNextLine(t, `OnChain:\s+false`) e.CheckNextLine(t, `OnChain:\s+false`)
@ -74,7 +74,7 @@ func TestQueryTx(t *testing.T) {
t.Run("FAULT", func(t *testing.T) { t.Run("FAULT", func(t *testing.T) {
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "contract", "invokefunction", e.Run(t, "neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", testcli.ValidatorAddr, "--address", testcli.ValidatorAddr,
"--force", "--force",
@ -144,7 +144,7 @@ func compareQueryTxVerbose(t *testing.T, e *testcli.Executor, tx *transaction.Tr
func TestQueryHeight(t *testing.T) { func TestQueryHeight(t *testing.T) {
e := testcli.NewExecutor(t, true) e := testcli.NewExecutor(t, true)
args := []string{"neo-go", "query", "height", "--rpc-endpoint", "http://" + e.RPC.Addr} args := []string{"neo-go", "query", "height", "--rpc-endpoint", "http://" + e.RPC.Addresses()[0]}
e.Run(t, args...) e.Run(t, args...)
e.CheckNextLine(t, `^Latest block: [0-9]+$`) e.CheckNextLine(t, `^Latest block: [0-9]+$`)
e.CheckNextLine(t, `^Validated state: [0-9]+$`) e.CheckNextLine(t, `^Validated state: [0-9]+$`)

View file

@ -141,8 +141,14 @@ func initBCWithMetrics(cfg config.Config, log *zap.Logger) (*core.Blockchain, *m
pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof, log) pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof, log)
go chain.Run() go chain.Run()
go prometheus.Start() err = prometheus.Start()
go pprof.Start() if err != nil {
return nil, nil, nil, cli.NewExitError(fmt.Errorf("failed to start Prometheus service: %w", err), 1)
}
err = pprof.Start()
if err != nil {
return nil, nil, nil, cli.NewExitError(fmt.Errorf("failed to start Pprof service: %w", err), 1)
}
return chain, prometheus, pprof, nil return chain, prometheus, pprof, nil
} }
@ -540,10 +546,18 @@ Main:
} }
pprof.ShutDown() pprof.ShutDown()
pprof = metrics.NewPprofService(cfgnew.ApplicationConfiguration.Pprof, log) pprof = metrics.NewPprofService(cfgnew.ApplicationConfiguration.Pprof, log)
go pprof.Start() err = pprof.Start()
if err != nil {
shutdownErr = fmt.Errorf("failed to start Pprof service: %w", err)
cancel() // Fatal error, like for RPC server.
}
prometheus.ShutDown() prometheus.ShutDown()
prometheus = metrics.NewPrometheusService(cfgnew.ApplicationConfiguration.Prometheus, log) prometheus = metrics.NewPrometheusService(cfgnew.ApplicationConfiguration.Prometheus, log)
go prometheus.Start() err = prometheus.Start()
if err != nil {
shutdownErr = fmt.Errorf("failed to start Prometheus service: %w", err)
cancel() // Fatal error, like for RPC server.
}
case sigusr1: case sigusr1:
if oracleSrv != nil { if oracleSrv != nil {
serv.DelService(oracleSrv) serv.DelService(oracleSrv)
@ -622,14 +636,14 @@ Main:
// use global one. So Node and RPC and Prometheus and Pprof will run on one address. // use global one. So Node and RPC and Prometheus and Pprof will run on one address.
func configureAddresses(cfg *config.ApplicationConfiguration) { func configureAddresses(cfg *config.ApplicationConfiguration) {
if cfg.Address != "" { if cfg.Address != "" {
if cfg.RPC.Address == "" { if cfg.RPC.Address == nil || *cfg.RPC.Address == "" {
cfg.RPC.Address = cfg.Address cfg.RPC.Address = &cfg.Address
} }
if cfg.Prometheus.Address == "" { if cfg.Prometheus.Address == nil || *cfg.Prometheus.Address == "" {
cfg.Prometheus.Address = cfg.Address cfg.Prometheus.Address = &cfg.Address
} }
if cfg.Pprof.Address == "" { if cfg.Pprof.Address == nil || *cfg.Pprof.Address == "" {
cfg.Pprof.Address = cfg.Address cfg.Pprof.Address = &cfg.Address
} }
} }
} }

View file

@ -321,9 +321,9 @@ func TestConfigureAddresses(t *testing.T) {
Address: defaultAddress, Address: defaultAddress,
} }
configureAddresses(cfg) configureAddresses(cfg)
require.Equal(t, defaultAddress, cfg.RPC.Address) require.Equal(t, defaultAddress, *cfg.RPC.Address) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
require.Equal(t, defaultAddress, cfg.Prometheus.Address) require.Equal(t, defaultAddress, *cfg.Prometheus.Address) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
require.Equal(t, defaultAddress, cfg.Pprof.Address) require.Equal(t, defaultAddress, *cfg.Pprof.Address) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
}) })
t.Run("custom RPC address", func(t *testing.T) { t.Run("custom RPC address", func(t *testing.T) {
@ -331,40 +331,40 @@ func TestConfigureAddresses(t *testing.T) {
Address: defaultAddress, Address: defaultAddress,
RPC: config.RPC{ RPC: config.RPC{
BasicService: config.BasicService{ BasicService: config.BasicService{
Address: customAddress, Address: &customAddress,
}, },
}, },
} }
configureAddresses(cfg) configureAddresses(cfg)
require.Equal(t, cfg.RPC.Address, customAddress) require.Equal(t, *cfg.RPC.Address, customAddress) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
require.Equal(t, cfg.Prometheus.Address, defaultAddress) require.Equal(t, *cfg.Prometheus.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
require.Equal(t, cfg.Pprof.Address, defaultAddress) require.Equal(t, *cfg.Pprof.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
}) })
t.Run("custom Pprof address", func(t *testing.T) { t.Run("custom Pprof address", func(t *testing.T) {
cfg := &config.ApplicationConfiguration{ cfg := &config.ApplicationConfiguration{
Address: defaultAddress, Address: defaultAddress,
Pprof: config.BasicService{ Pprof: config.BasicService{
Address: customAddress, Address: &customAddress,
}, },
} }
configureAddresses(cfg) configureAddresses(cfg)
require.Equal(t, cfg.RPC.Address, defaultAddress) require.Equal(t, *cfg.RPC.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
require.Equal(t, cfg.Prometheus.Address, defaultAddress) require.Equal(t, *cfg.Prometheus.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
require.Equal(t, cfg.Pprof.Address, customAddress) require.Equal(t, *cfg.Pprof.Address, customAddress) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
}) })
t.Run("custom Prometheus address", func(t *testing.T) { t.Run("custom Prometheus address", func(t *testing.T) {
cfg := &config.ApplicationConfiguration{ cfg := &config.ApplicationConfiguration{
Address: defaultAddress, Address: defaultAddress,
Prometheus: config.BasicService{ Prometheus: config.BasicService{
Address: customAddress, Address: &customAddress,
}, },
} }
configureAddresses(cfg) configureAddresses(cfg)
require.Equal(t, cfg.RPC.Address, defaultAddress) require.Equal(t, *cfg.RPC.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.RPC.Address is deprecated
require.Equal(t, cfg.Prometheus.Address, customAddress) require.Equal(t, *cfg.Prometheus.Address, customAddress) //nolint:staticcheck // SA1019: cfg.Prometheus.Address is deprecated
require.Equal(t, cfg.Pprof.Address, defaultAddress) require.Equal(t, *cfg.Pprof.Address, defaultAddress) //nolint:staticcheck // SA1019: cfg.Pprof.Address is deprecated
}) })
} }

View file

@ -310,7 +310,7 @@ func TestDeployBigContract(t *testing.T) {
e.In.WriteString(testcli.ValidatorPass + "\r") e.In.WriteString(testcli.ValidatorPass + "\r")
e.RunWithError(t, "neo-go", "contract", "deploy", e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName) "--in", nefName, "--manifest", manifestName)
} }
@ -333,7 +333,7 @@ func TestContractDeployWithData(t *testing.T) {
e := testcli.NewExecutor(t, true) e := testcli.NewExecutor(t, true)
cmd := []string{ cmd := []string{
"neo-go", "contract", "deploy", "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName, "--in", nefName, "--manifest", manifestName,
"--force", "--force",
@ -363,7 +363,7 @@ func TestContractDeployWithData(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
e.Run(t, "neo-go", "contract", "testinvokefunction", e.Run(t, "neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
h.StringLE(), h.StringLE(),
"getValueWithKey", "key1", "getValueWithKey", "key1",
) )
@ -375,7 +375,7 @@ func TestContractDeployWithData(t *testing.T) {
require.Equal(t, []byte{12}, res.Stack[0].Value()) require.Equal(t, []byte{12}, res.Stack[0].Value())
e.Run(t, "neo-go", "contract", "testinvokefunction", e.Run(t, "neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
h.StringLE(), h.StringLE(),
"getValueWithKey", "key2", "getValueWithKey", "key2",
) )
@ -408,33 +408,33 @@ func TestDeployWithSigners(t *testing.T) {
t.Run("missing nef", func(t *testing.T) { t.Run("missing nef", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "deploy", e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", "", "--manifest", manifestName) "--in", "", "--manifest", manifestName)
}) })
t.Run("missing manifest", func(t *testing.T) { t.Run("missing manifest", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "deploy", e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", "") "--in", nefName, "--manifest", "")
}) })
t.Run("corrupted data", func(t *testing.T) { t.Run("corrupted data", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "deploy", e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName, "--in", nefName, "--manifest", manifestName,
"[", "str1") "[", "str1")
}) })
t.Run("invalid data", func(t *testing.T) { t.Run("invalid data", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "deploy", e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName, "--in", nefName, "--manifest", manifestName,
"str1", "str2") "str1", "str2")
}) })
t.Run("missing wallet", func(t *testing.T) { t.Run("missing wallet", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "deploy", e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--address", testcli.ValidatorAddr, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName, "--in", nefName, "--manifest", manifestName,
"[", "str1", "str2", "]") "[", "str1", "str2", "]")
@ -447,7 +447,7 @@ func TestDeployWithSigners(t *testing.T) {
}) })
e.In.WriteString(testcli.ValidatorPass + "\r") e.In.WriteString(testcli.ValidatorPass + "\r")
e.Run(t, "neo-go", "contract", "deploy", e.Run(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName, "--in", nefName, "--manifest", manifestName,
"--force", "--force",
@ -534,7 +534,7 @@ func TestContractManifestGroups(t *testing.T) {
e.In.WriteString(testcli.ValidatorPass + "\r") e.In.WriteString(testcli.ValidatorPass + "\r")
e.Run(t, "neo-go", "contract", "deploy", e.Run(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", nefName, "--manifest", manifestName, "--in", nefName, "--manifest", manifestName,
"--force", "--force",
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr) "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr)
@ -557,22 +557,22 @@ func TestContract_TestInvokeScript(t *testing.T) {
t.Run("missing in", func(t *testing.T) { t.Run("missing in", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "testinvokescript", e.RunWithError(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr) "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
}) })
t.Run("unexisting in", func(t *testing.T) { t.Run("unexisting in", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "testinvokescript", e.RunWithError(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", badNef) "--in", badNef)
}) })
t.Run("invalid nef", func(t *testing.T) { t.Run("invalid nef", func(t *testing.T) {
require.NoError(t, os.WriteFile(badNef, []byte("qwer"), os.ModePerm)) require.NoError(t, os.WriteFile(badNef, []byte("qwer"), os.ModePerm))
e.RunWithError(t, "neo-go", "contract", "testinvokescript", e.RunWithError(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", badNef) "--in", badNef)
}) })
t.Run("invalid signers", func(t *testing.T) { t.Run("invalid signers", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "testinvokescript", e.RunWithError(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", goodNef, "--", "not-a-valid-signer") "--in", goodNef, "--", "not-a-valid-signer")
}) })
t.Run("no RPC endpoint", func(t *testing.T) { t.Run("no RPC endpoint", func(t *testing.T) {
@ -582,34 +582,34 @@ func TestContract_TestInvokeScript(t *testing.T) {
}) })
t.Run("good", func(t *testing.T) { t.Run("good", func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokescript", e.Run(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", goodNef) "--in", goodNef)
}) })
t.Run("good with hashed signer", func(t *testing.T) { t.Run("good with hashed signer", func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokescript", e.Run(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", goodNef, "--", util.Uint160{1, 2, 3}.StringLE()) "--in", goodNef, "--", util.Uint160{1, 2, 3}.StringLE())
}) })
t.Run("good with addressed signer", func(t *testing.T) { t.Run("good with addressed signer", func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokescript", e.Run(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--in", goodNef, "--", address.Uint160ToString(util.Uint160{1, 2, 3})) "--in", goodNef, "--", address.Uint160ToString(util.Uint160{1, 2, 3}))
}) })
t.Run("historic, invalid", func(t *testing.T) { t.Run("historic, invalid", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "testinvokescript", e.RunWithError(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--historic", "bad", "--historic", "bad",
"--in", goodNef) "--in", goodNef)
}) })
t.Run("historic, index", func(t *testing.T) { t.Run("historic, index", func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokescript", e.Run(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--historic", "0", "--historic", "0",
"--in", goodNef) "--in", goodNef)
}) })
t.Run("historic, hash", func(t *testing.T) { t.Run("historic, hash", func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokescript", e.Run(t, "neo-go", "contract", "testinvokescript",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--historic", e.Chain.GetHeaderHash(0).StringLE(), "--historic", e.Chain.GetHeaderHash(0).StringLE(),
"--in", goodNef) "--in", goodNef)
}) })
@ -639,7 +639,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, os.WriteFile(configPath, yml, 0666)) require.NoError(t, os.WriteFile(configPath, yml, 0666))
e.Run(t, "neo-go", "contract", "deploy", e.Run(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--force", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "--force",
"--wallet-config", configPath, "--address", testcli.ValidatorAddr, "--wallet-config", configPath, "--address", testcli.ValidatorAddr,
"--in", nefName, "--manifest", manifestName) "--in", nefName, "--manifest", manifestName)
@ -663,7 +663,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
}) })
cmd := []string{"neo-go", "contract", "testinvokefunction", cmd := []string{"neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://" + e.RPC.Addr} "--rpc-endpoint", "http://" + e.RPC.Addresses()[0]}
t.Run("missing hash", func(t *testing.T) { t.Run("missing hash", func(t *testing.T) {
e.RunWithError(t, cmd...) e.RunWithError(t, cmd...)
}) })
@ -704,7 +704,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
t.Run("real invoke", func(t *testing.T) { t.Run("real invoke", func(t *testing.T) {
cmd := []string{"neo-go", "contract", "invokefunction", cmd := []string{"neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://" + e.RPC.Addr} "--rpc-endpoint", "http://" + e.RPC.Addresses()[0]}
t.Run("missing wallet", func(t *testing.T) { t.Run("missing wallet", func(t *testing.T) {
cmd := append(cmd, h.StringLE(), "getValue") cmd := append(cmd, h.StringLE(), "getValue")
e.RunWithError(t, cmd...) e.RunWithError(t, cmd...)
@ -778,7 +778,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
txout := filepath.Join(tmpDir, "test_contract_tx.json") txout := filepath.Join(tmpDir, "test_contract_tx.json")
cmd = []string{"neo-go", "contract", "invokefunction", cmd = []string{"neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--out", txout, "--out", txout,
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
} }
@ -837,7 +837,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
t.Run("test Storage.Find", func(t *testing.T) { t.Run("test Storage.Find", func(t *testing.T) {
cmd := []string{"neo-go", "contract", "testinvokefunction", cmd := []string{"neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
h.StringLE(), "testFind"} h.StringLE(), "testFind"}
t.Run("keys only", func(t *testing.T) { t.Run("keys only", func(t *testing.T) {
@ -901,7 +901,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
stateBeforeUpdate = mptBeforeUpdate.Root stateBeforeUpdate = mptBeforeUpdate.Root
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "contract", "invokefunction", e.Run(t, "neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--address", testcli.ValidatorAddr,
"--force", "--force",
h.StringLE(), "update", h.StringLE(), "update",
@ -913,14 +913,14 @@ func TestComlileAndInvokeFunction(t *testing.T) {
indexAfterUpdate = e.Chain.BlockHeight() indexAfterUpdate = e.Chain.BlockHeight()
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "contract", "testinvokefunction", e.Run(t, "neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
h.StringLE(), "getValue") h.StringLE(), "getValue")
checkGetValueOut("on update|sub update") checkGetValueOut("on update|sub update")
}) })
t.Run("historic", func(t *testing.T) { t.Run("historic", func(t *testing.T) {
t.Run("bad ref", func(t *testing.T) { t.Run("bad ref", func(t *testing.T) {
e.RunWithError(t, "neo-go", "contract", "testinvokefunction", e.RunWithError(t, "neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--historic", "bad", "--historic", "bad",
h.StringLE(), "getValue") h.StringLE(), "getValue")
}) })
@ -931,7 +931,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
} { } {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokefunction", e.Run(t, "neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--historic", ref, "--historic", ref,
h.StringLE(), "getValue") h.StringLE(), "getValue")
}) })
@ -939,7 +939,7 @@ func TestComlileAndInvokeFunction(t *testing.T) {
} }
t.Run("updated historic", func(t *testing.T) { t.Run("updated historic", func(t *testing.T) {
e.Run(t, "neo-go", "contract", "testinvokefunction", e.Run(t, "neo-go", "contract", "testinvokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--historic", strconv.FormatUint(uint64(indexAfterUpdate), 10), "--historic", strconv.FormatUint(uint64(indexAfterUpdate), 10),
h.StringLE(), "getValue") h.StringLE(), "getValue")
checkGetValueOut("on update|sub update") checkGetValueOut("on update|sub update")

View file

@ -22,7 +22,7 @@ func TestRegisterCandidate(t *testing.T) {
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--force", "--force",
@ -31,29 +31,29 @@ func TestRegisterCandidate(t *testing.T) {
e.CheckTxPersisted(t) e.CheckTxPersisted(t)
e.Run(t, "neo-go", "query", "committee", e.Run(t, "neo-go", "query", "committee",
"--rpc-endpoint", "http://"+e.RPC.Addr) "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
e.CheckNextLine(t, "^\\s*"+validatorHex) e.CheckNextLine(t, "^\\s*"+validatorHex)
e.Run(t, "neo-go", "query", "candidates", e.Run(t, "neo-go", "query", "candidates",
"--rpc-endpoint", "http://"+e.RPC.Addr) "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
e.CheckNextLine(t, "^\\s*Key.+$") // Header. e.CheckNextLine(t, "^\\s*Key.+$") // Header.
e.CheckEOF(t) e.CheckEOF(t)
// missing address // missing address
e.RunWithError(t, "neo-go", "wallet", "candidate", "register", e.RunWithError(t, "neo-go", "wallet", "candidate", "register",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet) "--wallet", testcli.ValidatorWallet)
// additional parameter // additional parameter
e.RunWithError(t, "neo-go", "wallet", "candidate", "register", e.RunWithError(t, "neo-go", "wallet", "candidate", "register",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
"error") "error")
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "candidate", "register", e.Run(t, "neo-go", "wallet", "candidate", "register",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
"--force") "--force")
@ -68,14 +68,14 @@ func TestRegisterCandidate(t *testing.T) {
t.Run("VoteUnvote", func(t *testing.T) { t.Run("VoteUnvote", func(t *testing.T) {
// positional instead of a flag. // positional instead of a flag.
e.RunWithError(t, "neo-go", "wallet", "candidate", "vote", e.RunWithError(t, "neo-go", "wallet", "candidate", "vote",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
validatorHex) // not "--candidate hex", but "hex". validatorHex) // not "--candidate hex", but "hex".
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "candidate", "vote", e.Run(t, "neo-go", "wallet", "candidate", "vote",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
"--candidate", validatorHex, "--candidate", validatorHex,
@ -89,18 +89,18 @@ func TestRegisterCandidate(t *testing.T) {
require.Equal(t, b, vs[0].Votes) require.Equal(t, b, vs[0].Votes)
e.Run(t, "neo-go", "query", "committee", e.Run(t, "neo-go", "query", "committee",
"--rpc-endpoint", "http://"+e.RPC.Addr) "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
e.CheckNextLine(t, "^\\s*"+validatorHex) e.CheckNextLine(t, "^\\s*"+validatorHex)
e.Run(t, "neo-go", "query", "candidates", e.Run(t, "neo-go", "query", "candidates",
"--rpc-endpoint", "http://"+e.RPC.Addr) "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
e.CheckNextLine(t, "^\\s*Key.+$") // Header. e.CheckNextLine(t, "^\\s*Key.+$") // Header.
e.CheckNextLine(t, "^\\s*"+validatorHex+"\\s*"+b.String()+"\\s*true\\s*true$") e.CheckNextLine(t, "^\\s*"+validatorHex+"\\s*"+b.String()+"\\s*true\\s*true$")
e.CheckEOF(t) e.CheckEOF(t)
// check state // check state
e.Run(t, "neo-go", "query", "voter", e.Run(t, "neo-go", "query", "voter",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
validatorAddress) validatorAddress)
e.CheckNextLine(t, "^\\s*Voted:\\s+"+validatorHex+"\\s+\\("+validatorAddress+"\\)$") e.CheckNextLine(t, "^\\s*Voted:\\s+"+validatorHex+"\\s+\\("+validatorAddress+"\\)$")
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$") e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
@ -110,7 +110,7 @@ func TestRegisterCandidate(t *testing.T) {
// unvote // unvote
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "candidate", "vote", e.Run(t, "neo-go", "wallet", "candidate", "vote",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
"--force") "--force")
@ -123,7 +123,7 @@ func TestRegisterCandidate(t *testing.T) {
// check state // check state
e.Run(t, "neo-go", "query", "voter", e.Run(t, "neo-go", "query", "voter",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
validatorAddress) validatorAddress)
e.CheckNextLine(t, "^\\s*Voted:\\s+"+"null") // no vote. e.CheckNextLine(t, "^\\s*Voted:\\s+"+"null") // no vote.
e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$") e.CheckNextLine(t, "^\\s*Amount\\s*:\\s*"+b.String()+"$")
@ -133,18 +133,18 @@ func TestRegisterCandidate(t *testing.T) {
// missing address // missing address
e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister", e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet) "--wallet", testcli.ValidatorWallet)
// additional argument // additional argument
e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister", e.RunWithError(t, "neo-go", "wallet", "candidate", "unregister",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
"argument") "argument")
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "candidate", "unregister", e.Run(t, "neo-go", "wallet", "candidate", "unregister",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--address", validatorAddress, "--address", validatorAddress,
"--force") "--force")
@ -156,7 +156,7 @@ func TestRegisterCandidate(t *testing.T) {
// query voter: missing address // query voter: missing address
e.RunWithError(t, "neo-go", "query", "voter") e.RunWithError(t, "neo-go", "query", "voter")
// Excessive parameters. // Excessive parameters.
e.RunWithError(t, "neo-go", "query", "voter", "--rpc-endpoint", "http://"+e.RPC.Addr, validatorAddress, validatorAddress) e.RunWithError(t, "neo-go", "query", "voter", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], validatorAddress, validatorAddress)
e.RunWithError(t, "neo-go", "query", "committee", "--rpc-endpoint", "http://"+e.RPC.Addr, "something") e.RunWithError(t, "neo-go", "query", "committee", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "something")
e.RunWithError(t, "neo-go", "query", "candidates", "--rpc-endpoint", "http://"+e.RPC.Addr, "something") e.RunWithError(t, "neo-go", "query", "candidates", "--rpc-endpoint", "http://"+e.RPC.Addresses()[0], "something")
} }

View file

@ -55,7 +55,7 @@ func TestSignMultisigTx(t *testing.T) {
// Transfer funds to the multisig. // Transfer funds to the multisig.
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--force", "--force",
@ -74,7 +74,7 @@ func TestSignMultisigTx(t *testing.T) {
}) })
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet1Path, "--from", multisigAddr, "--wallet", wallet1Path, "--from", multisigAddr,
"--to", priv.Address(), "--token", "NEO", "--amount", "1", "--to", priv.Address(), "--token", "NEO", "--amount", "1",
"--out", txPath) "--out", txPath)
@ -99,7 +99,7 @@ func TestSignMultisigTx(t *testing.T) {
// invalid out // invalid out
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.RunWithError(t, "neo-go", "wallet", "sign", e.RunWithError(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet2Path, "--address", multisigAddr, "--wallet", wallet2Path, "--address", multisigAddr,
"--in", txPath, "--out", t.TempDir()) "--in", txPath, "--out", t.TempDir())
@ -118,7 +118,7 @@ func TestSignMultisigTx(t *testing.T) {
}) })
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet1Path, "--from", multisigAddr, "--wallet", wallet1Path, "--from", multisigAddr,
"--to", priv.Address(), "--token", "NEO", "--amount", "1", "--to", priv.Address(), "--token", "NEO", "--amount", "1",
"--out", txPath) "--out", txPath)
@ -152,11 +152,11 @@ func TestSignMultisigTx(t *testing.T) {
t.Run("excessive parameters", func(t *testing.T) { t.Run("excessive parameters", func(t *testing.T) {
e.RunWithError(t, "neo-go", "util", "txdump", e.RunWithError(t, "neo-go", "util", "txdump",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
txPath, "garbage") txPath, "garbage")
}) })
e.Run(t, "neo-go", "util", "txdump", e.Run(t, "neo-go", "util", "txdump",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
txPath) txPath)
e.CheckTxTestInvokeOutput(t, 11) e.CheckTxTestInvokeOutput(t, 11)
res := new(result.Invoke) res := new(result.Invoke)
@ -194,7 +194,7 @@ func TestSignMultisigTx(t *testing.T) {
t.Run("sign, save and send", func(t *testing.T) { t.Run("sign, save and send", func(t *testing.T) {
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "sign", e.Run(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet2Path, "--address", multisigAddr, "--wallet", wallet2Path, "--address", multisigAddr,
"--in", txPath, "--out", txPath) "--in", txPath, "--out", txPath)
e.CheckTxPersisted(t) e.CheckTxPersisted(t)
@ -202,7 +202,7 @@ func TestSignMultisigTx(t *testing.T) {
t.Run("double-sign", func(t *testing.T) { t.Run("double-sign", func(t *testing.T) {
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.RunWithError(t, "neo-go", "wallet", "sign", e.RunWithError(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet2Path, "--address", multisigAddr, "--wallet", wallet2Path, "--address", multisigAddr,
"--in", txPath, "--out", txPath) "--in", txPath, "--out", txPath)
}) })
@ -217,13 +217,13 @@ func TestSignMultisigTx(t *testing.T) {
e.In.WriteString("acc\rpass\rpass\r") e.In.WriteString("acc\rpass\rpass\r")
e.Run(t, "neo-go", "wallet", "import-deployed", e.Run(t, "neo-go", "wallet", "import-deployed",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet1Path, "--wif", simplePriv.WIF(), "--wallet", wallet1Path, "--wif", simplePriv.WIF(),
"--contract", h.StringLE()) "--contract", h.StringLE())
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "contract", "invokefunction", e.Run(t, "neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet1Path, "--address", multisigHash.StringLE(), // test with scripthash instead of address "--wallet", wallet1Path, "--address", multisigHash.StringLE(), // test with scripthash instead of address
"--out", txPath, "--out", txPath,
e.Chain.GoverningTokenHash().StringLE(), "transfer", e.Chain.GoverningTokenHash().StringLE(), "transfer",
@ -249,7 +249,7 @@ func TestSignMultisigTx(t *testing.T) {
// Contract. // Contract.
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "sign", e.Run(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet1Path, "--address", address.Uint160ToString(h), "--wallet", wallet1Path, "--address", address.Uint160ToString(h),
"--in", txPath, "--out", txPath) "--in", txPath, "--out", txPath)
tx, _ := e.CheckTxPersisted(t) tx, _ := e.CheckTxPersisted(t)

View file

@ -470,17 +470,17 @@ func TestWalletClaimGas(t *testing.T) {
t.Run("missing wallet path", func(t *testing.T) { t.Run("missing wallet path", func(t *testing.T) {
e.RunWithError(t, "neo-go", "wallet", "claim", e.RunWithError(t, "neo-go", "wallet", "claim",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--address", testcli.TestWalletAccount) "--address", testcli.TestWalletAccount)
}) })
t.Run("missing address", func(t *testing.T) { t.Run("missing address", func(t *testing.T) {
e.RunWithError(t, "neo-go", "wallet", "claim", e.RunWithError(t, "neo-go", "wallet", "claim",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.TestWalletPath) "--wallet", testcli.TestWalletPath)
}) })
t.Run("invalid address", func(t *testing.T) { t.Run("invalid address", func(t *testing.T) {
e.RunWithError(t, "neo-go", "wallet", "claim", e.RunWithError(t, "neo-go", "wallet", "claim",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.TestWalletPath, "--wallet", testcli.TestWalletPath,
"--address", util.Uint160{}.StringLE()) "--address", util.Uint160{}.StringLE())
}) })
@ -493,14 +493,14 @@ func TestWalletClaimGas(t *testing.T) {
t.Run("insufficient funds", func(t *testing.T) { t.Run("insufficient funds", func(t *testing.T) {
e.In.WriteString("testpass\r") e.In.WriteString("testpass\r")
e.RunWithError(t, "neo-go", "wallet", "claim", e.RunWithError(t, "neo-go", "wallet", "claim",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.TestWalletPath, "--wallet", testcli.TestWalletPath,
"--address", testcli.TestWalletAccount) "--address", testcli.TestWalletAccount)
}) })
args := []string{ args := []string{
"neo-go", "wallet", "nep17", "multitransfer", "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--wallet", testcli.ValidatorWallet,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--force", "--force",
@ -522,7 +522,7 @@ func TestWalletClaimGas(t *testing.T) {
e.In.WriteString("testpass\r") e.In.WriteString("testpass\r")
e.Run(t, "neo-go", "wallet", "claim", e.Run(t, "neo-go", "wallet", "claim",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.TestWalletPath, "--wallet", testcli.TestWalletPath,
"--address", testcli.TestWalletAccount, "--address", testcli.TestWalletAccount,
"--force") "--force")
@ -570,7 +570,7 @@ func TestWalletImportDeployed(t *testing.T) {
t.Run("unknown contract", func(t *testing.T) { t.Run("unknown contract", func(t *testing.T) {
e.In.WriteString("acc\rpass\rpass\r") e.In.WriteString("acc\rpass\rpass\r")
e.RunWithError(t, "neo-go", "wallet", "import-deployed", e.RunWithError(t, "neo-go", "wallet", "import-deployed",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--contract", util.Uint160{}.StringLE(), "--wallet", walletPath, "--contract", util.Uint160{}.StringLE(),
"--wif", priv.WIF()) "--wif", priv.WIF())
}) })
@ -578,14 +578,14 @@ func TestWalletImportDeployed(t *testing.T) {
badH := deployNNSContract(t, e) // wrong contract with no `verify` method badH := deployNNSContract(t, e) // wrong contract with no `verify` method
e.In.WriteString("acc\rpass\rpass\r") e.In.WriteString("acc\rpass\rpass\r")
e.RunWithError(t, "neo-go", "wallet", "import-deployed", e.RunWithError(t, "neo-go", "wallet", "import-deployed",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--contract", badH.StringLE(), "--wallet", walletPath, "--contract", badH.StringLE(),
"--wif", priv.WIF()) "--wif", priv.WIF())
}) })
e.In.WriteString("acc\rpass\rpass\r") e.In.WriteString("acc\rpass\rpass\r")
e.Run(t, "neo-go", "wallet", "import-deployed", e.Run(t, "neo-go", "wallet", "import-deployed",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--wif", priv.WIF(), "--name", "my_acc", "--wallet", walletPath, "--wif", priv.WIF(), "--name", "my_acc",
"--contract", h.StringLE()) "--contract", h.StringLE())
@ -599,7 +599,7 @@ func TestWalletImportDeployed(t *testing.T) {
t.Run("re-importing", func(t *testing.T) { t.Run("re-importing", func(t *testing.T) {
e.In.WriteString("acc\rpass\rpass\r") e.In.WriteString("acc\rpass\rpass\r")
e.RunWithError(t, "neo-go", "wallet", "import-deployed", e.RunWithError(t, "neo-go", "wallet", "import-deployed",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--wif", priv.WIF(), "--name", "my_acc", "--wallet", walletPath, "--wif", priv.WIF(), "--name", "my_acc",
"--contract", h.StringLE()) "--contract", h.StringLE())
}) })
@ -607,7 +607,7 @@ func TestWalletImportDeployed(t *testing.T) {
t.Run("Sign", func(t *testing.T) { t.Run("Sign", func(t *testing.T) {
e.In.WriteString("one\r") e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer", e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", testcli.ValidatorWallet, "--from", testcli.ValidatorAddr, "--wallet", testcli.ValidatorWallet, "--from", testcli.ValidatorAddr,
"--force", "--force",
"NEO:"+contractAddr+":10", "NEO:"+contractAddr+":10",
@ -619,7 +619,7 @@ func TestWalletImportDeployed(t *testing.T) {
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "nep17", "transfer", e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--from", contractAddr, "--wallet", walletPath, "--from", contractAddr,
"--force", "--force",
"--to", privTo.Address(), "--token", "NEO", "--amount", "1") "--to", privTo.Address(), "--token", "NEO", "--amount", "1")
@ -680,7 +680,7 @@ func TestOfflineSigning(t *testing.T) {
t.Run("1/1 multisig", func(t *testing.T) { t.Run("1/1 multisig", func(t *testing.T) {
args := []string{"neo-go", "wallet", "nep17", "transfer", args := []string{"neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
"--from", testcli.ValidatorAddr, "--from", testcli.ValidatorAddr,
"--to", w.Accounts[0].Address, "--to", w.Accounts[0].Address,
@ -699,15 +699,15 @@ func TestOfflineSigning(t *testing.T) {
t.Run("sendtx", func(t *testing.T) { t.Run("sendtx", func(t *testing.T) {
// And it can't be sent. // And it can't be sent.
e.RunWithError(t, "neo-go", "util", "sendtx", e.RunWithError(t, "neo-go", "util", "sendtx",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
txPath) txPath)
// Even with too many arguments. // Even with too many arguments.
e.RunWithError(t, "neo-go", "util", "sendtx", e.RunWithError(t, "neo-go", "util", "sendtx",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
txPath, txPath) txPath, txPath)
// Or no arguments at all. // Or no arguments at all.
e.RunWithError(t, "neo-go", "util", "sendtx", e.RunWithError(t, "neo-go", "util", "sendtx",
"--rpc-endpoint", "http://"+e.RPC.Addr) "--rpc-endpoint", "http://"+e.RPC.Addresses()[0])
}) })
// But it can be signed with a proper wallet. // But it can be signed with a proper wallet.
e.In.WriteString("one\r") e.In.WriteString("one\r")
@ -716,7 +716,7 @@ func TestOfflineSigning(t *testing.T) {
"--in", txPath, "--out", txPath) "--in", txPath, "--out", txPath)
// And then anyone can send (even via wallet sign). // And then anyone can send (even via wallet sign).
e.Run(t, "neo-go", "wallet", "sign", e.Run(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", walletPath, "--address", testcli.ValidatorAddr, "--wallet", walletPath, "--address", testcli.ValidatorAddr,
"--in", txPath) "--in", txPath)
}) })
@ -724,7 +724,7 @@ func TestOfflineSigning(t *testing.T) {
t.Run("simple signature", func(t *testing.T) { t.Run("simple signature", func(t *testing.T) {
simpleAddr := w.Accounts[0].Address simpleAddr := w.Accounts[0].Address
args := []string{"neo-go", "wallet", "nep17", "transfer", args := []string{"neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr, "--rpc-endpoint", "http://" + e.RPC.Addresses()[0],
"--wallet", walletPath, "--wallet", walletPath,
"--from", simpleAddr, "--from", simpleAddr,
"--to", testcli.ValidatorAddr, "--to", testcli.ValidatorAddr,
@ -749,7 +749,7 @@ func TestOfflineSigning(t *testing.T) {
e.RunWithError(t, "neo-go", "util", "sendtx", txPath) e.RunWithError(t, "neo-go", "util", "sendtx", txPath)
// But it requires no wallet at all. // But it requires no wallet at all.
e.Run(t, "neo-go", "util", "sendtx", e.Run(t, "neo-go", "util", "sendtx",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
txPath) txPath)
}) })
} }

View file

@ -64,17 +64,21 @@ ApplicationConfiguration:
- application/json - application/json
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":40332"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 40332
TLSConfig: TLSConfig:
Enabled: false Enabled: false
Port: 40331 Addresses:
- ":40331"
CertFile: serv.crt CertFile: serv.crt
KeyFile: serv.key KeyFile: serv.key
Prometheus: Prometheus:
Enabled: false Enabled: false
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 2113 Addresses:
- ":2113"

View file

@ -82,17 +82,21 @@ ApplicationConfiguration:
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":10332"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 10332
TLSConfig: TLSConfig:
Enabled: false Enabled: false
Port: 10331 Addresses:
- ":10331"
CertFile: serv.crt CertFile: serv.crt
KeyFile: serv.key KeyFile: serv.key
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 2113 Addresses:
- ":2113"

View file

@ -69,15 +69,18 @@ ApplicationConfiguration:
Password: "pass" Password: "pass"
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":30336"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 30336
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 20004 Addresses:
- ":20004"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 20014 Addresses:
- ":20014"
UnlockWallet: UnlockWallet:
Path: "/wallet4.json" Path: "/wallet4.json"
Password: "four" Password: "four"

View file

@ -69,12 +69,14 @@ ApplicationConfiguration:
Password: "pass" Password: "pass"
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":30333"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 30333
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 20001 Addresses:
- ":20001"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 20011 Port: 20011

View file

@ -60,15 +60,18 @@ ApplicationConfiguration:
Password: "pass" Password: "pass"
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":30333"
EnableCORSWorkaround: false EnableCORSWorkaround: false
MaxGasInvoke: 15 MaxGasInvoke: 15
Port: 30333
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 20001 Addresses:
- ":20001"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 20011 Addresses:
- ":20011"
UnlockWallet: UnlockWallet:
Path: "/wallet1.json" Path: "/wallet1.json"
Password: "one" Password: "one"

View file

@ -69,15 +69,18 @@ ApplicationConfiguration:
Password: "pass" Password: "pass"
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":30335"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 30335
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 20003 Addresses:
- ":20003"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 20013 Addresses:
- ":20013"
UnlockWallet: UnlockWallet:
Path: "/wallet3.json" Path: "/wallet3.json"
Password: "three" Password: "three"

View file

@ -71,13 +71,16 @@ ApplicationConfiguration:
Enabled: true Enabled: true
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 30334 Addresses:
- ":30334"
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 20002 Addresses:
- ":20002"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 20012 Addresses:
- ":20012"
UnlockWallet: UnlockWallet:
Path: "/wallet2.json" Path: "/wallet2.json"
Password: "two" Password: "two"

View file

@ -56,19 +56,23 @@ ApplicationConfiguration:
Password: "pass" Password: "pass"
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":20331"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 20331
SessionEnabled: true SessionEnabled: true
SessionExpirationTime: 180 # higher expiration time for manual requests and tests. SessionExpirationTime: 180 # higher expiration time for manual requests and tests.
TLSConfig: TLSConfig:
Enabled: false Enabled: false
Port: 20330 Addresses:
- ":20330"
CertFile: serv.crt CertFile: serv.crt
KeyFile: serv.key KeyFile: serv.key
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 2113 Addresses:
- ":2113"

View file

@ -64,15 +64,17 @@ ApplicationConfiguration:
- application/json - application/json
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":50332"
EnableCORSWorkaround: false EnableCORSWorkaround: false
MaxGasInvoke: 100 MaxGasInvoke: 100
Port: 50332
StartWhenSynchronized: false StartWhenSynchronized: false
TLSConfig: TLSConfig:
Enabled: false Enabled: false
Addresses:
- ":50331"
CertFile: server.crt CertFile: server.crt
KeyFile: server.key KeyFile: server.key
Port: 50331
P2PNotary: P2PNotary:
Enabled: false Enabled: false
UnlockWallet: UnlockWallet:
@ -80,7 +82,9 @@ ApplicationConfiguration:
Path: "/notary_wallet.json" Path: "/notary_wallet.json"
Prometheus: Prometheus:
Enabled: false Enabled: false
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 2113 Addresses:
- ":2113"

View file

@ -84,17 +84,21 @@ ApplicationConfiguration:
Password: "pass" Password: "pass"
RPC: RPC:
Enabled: true Enabled: true
Addresses:
- ":20332"
MaxGasInvoke: 15 MaxGasInvoke: 15
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 20332
TLSConfig: TLSConfig:
Enabled: false Enabled: false
Port: 20331 Addresses:
- ":20331"
CertFile: serv.crt CertFile: serv.crt
KeyFile: serv.key KeyFile: serv.key
Prometheus: Prometheus:
Enabled: true Enabled: true
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false Enabled: false
Port: 2113 Addresses:
- ":2113"

View file

@ -53,14 +53,16 @@ ApplicationConfiguration:
Path: "/notary_wallet.json" Path: "/notary_wallet.json"
Password: "pass" Password: "pass"
RPC: RPC:
Address: localhost
MaxGasInvoke: 15 MaxGasInvoke: 15
Enabled: true Enabled: true
Addresses:
- "localhost:0" # let the system choose port dynamically
EnableCORSWorkaround: false EnableCORSWorkaround: false
Port: 0 # let the system choose port dynamically
Prometheus: Prometheus:
Enabled: false #since it's not useful for unit tests. Enabled: false #since it's not useful for unit tests.
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false #since it's not useful for unit tests. Enabled: false #since it's not useful for unit tests.
Port: 2113 Addresses:
- ":2113"

View file

@ -59,16 +59,18 @@ ApplicationConfiguration:
Path: "/notary_wallet.json" Path: "/notary_wallet.json"
Password: "pass" Password: "pass"
RPC: RPC:
Address: localhost
MaxGasInvoke: 15 MaxGasInvoke: 15
Enabled: true Enabled: true
Addresses:
- "localhost:0" # let the system choose port dynamically
EnableCORSWorkaround: false EnableCORSWorkaround: false
SessionEnabled: true SessionEnabled: true
SessionExpirationTime: 2 # enough for tests as they run locally. SessionExpirationTime: 2 # enough for tests as they run locally.
Port: 0 # let the system choose port dynamically
Prometheus: Prometheus:
Enabled: false #since it's not useful for unit tests. Enabled: false #since it's not useful for unit tests.
Port: 2112 Addresses:
- ":2112"
Pprof: Pprof:
Enabled: false #since it's not useful for unit tests. Enabled: false #since it's not useful for unit tests.
Port: 2113 Addresses:
- ":2113"

View file

@ -118,17 +118,21 @@ Prometheus) and has the following structure:
``` ```
Pprof: Pprof:
Enabled: false Enabled: false
Address: "" Addresses:
Port: "30001" - ":30001"
Prometheus: Prometheus:
Enabled: false Enabled: false
Address: "" Addresses:
Port: "40001" - ":40001"
``` ```
where: where:
- `Enabled` denotes whether the service is enabled. - `Enabled` denotes whether the service is enabled.
- `Address` is a service address to be running at. - `Address` is a service address to be running at. Warning: this field is deprecated,
- `Port` is a service port to be bound to. please, use `Addresses` instead.
- `Port` is a service port to be bound to. Warning: this field is deprecated, please,
use `Addresses` instead.
- `Addresses` is a list of service addresses to be running at and listen to in
the form of "host:port".
### RPC Configuration ### RPC Configuration
@ -137,29 +141,32 @@ the following structure:
``` ```
RPC: RPC:
Enabled: true Enabled: true
Address: "" Addresses:
- ":10332"
EnableCORSWorkaround: false EnableCORSWorkaround: false
MaxGasInvoke: 50 MaxGasInvoke: 50
MaxIteratorResultItems: 100 MaxIteratorResultItems: 100
MaxFindResultItems: 100 MaxFindResultItems: 100
MaxNEP11Tokens: 100 MaxNEP11Tokens: 100
MaxWebSocketClients: 64 MaxWebSocketClients: 64
Port: 10332
SessionEnabled: false SessionEnabled: false
SessionExpirationTime: 15 SessionExpirationTime: 15
SessionBackedByMPT: false SessionBackedByMPT: false
SessionPoolSize: 20 SessionPoolSize: 20
StartWhenSynchronized: false StartWhenSynchronized: false
TLSConfig: TLSConfig:
Address: "" Addresses:
- ":10331"
CertFile: serv.crt CertFile: serv.crt
Enabled: true Enabled: true
Port: 10331
KeyFile: serv.key KeyFile: serv.key
``` ```
where: where:
- `Enabled` denotes whether an RPC server should be started. - `Enabled` denotes whether an RPC server should be started.
- `Address` is an RPC server address to be running at. - `Address` is an RPC server address to be running at. Warning: this field is
deprecated, please, use `Addresses` instead.
- `Addresses` is a list of RPC server addresses to be running at and listen to in
the form of "host:port".
- `EnableCORSWorkaround` turns on a set of origin-related behaviors that make - `EnableCORSWorkaround` turns on a set of origin-related behaviors that make
RPC server wide open for connections from any origins. It enables OPTIONS RPC server wide open for connections from any origins. It enables OPTIONS
request handling for pre-flight CORS and makes the server send request handling for pre-flight CORS and makes the server send
@ -182,7 +189,8 @@ where:
number (64 by default). Attempts to establish additional connections will number (64 by default). Attempts to establish additional connections will
lead to websocket handshake failures. Use "-1" to disable websocket lead to websocket handshake failures. Use "-1" to disable websocket
connections (0 will lead to using the default value). connections (0 will lead to using the default value).
- `Port` is an RPC server port it should be bound to. - `Port` is an RPC server port it should be bound to. Warning: this field is
deprecated, please, use `Addresses` instead.
- `SessionEnabled` denotes whether session-based iterator JSON-RPC API is enabled. - `SessionEnabled` denotes whether session-based iterator JSON-RPC API is enabled.
If true, then all iterators got from `invoke*` calls will be stored as sessions If true, then all iterators got from `invoke*` calls will be stored as sessions
on the server side available for further traverse. `traverseiterator` and on the server side available for further traverse. `traverseiterator` and

View file

@ -348,7 +348,7 @@ func DeployContract(t *testing.T, e *Executor, inPath, configPath, wallet, addre
"--out", nefName, "--manifest", manifestName) "--out", nefName, "--manifest", manifestName)
e.In.WriteString(pass + "\r") e.In.WriteString(pass + "\r")
e.Run(t, "neo-go", "contract", "deploy", e.Run(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
"--wallet", wallet, "--address", address, "--wallet", wallet, "--address", address,
"--force", "--force",
"--in", nefName, "--manifest", manifestName) "--in", nefName, "--manifest", manifestName)

View file

@ -20,12 +20,3 @@ func TestApplicationConfigurationEquals(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.False(t, cfg1.ApplicationConfiguration.EqualsButServices(&cfg2.ApplicationConfiguration)) require.False(t, cfg1.ApplicationConfiguration.EqualsButServices(&cfg2.ApplicationConfiguration))
} }
// TestApplicationConfiguration_UnmarshalRPCBasicService is aimed to check that BasicService
// config of RPC service can be properly unmarshalled.
func TestApplicationConfiguration_UnmarshalRPCBasicService(t *testing.T) {
cfg, err := LoadFile(filepath.Join("..", "..", "config", "protocol.mainnet.yml"))
require.NoError(t, err)
require.True(t, cfg.ApplicationConfiguration.RPC.Enabled)
require.Equal(t, uint16(10332), cfg.ApplicationConfiguration.RPC.Port)
}

View file

@ -8,12 +8,32 @@ import (
// BasicService is used as a simple base for node services like Pprof, RPC or // BasicService is used as a simple base for node services like Pprof, RPC or
// Prometheus monitoring. // Prometheus monitoring.
type BasicService struct { type BasicService struct {
Enabled bool `yaml:"Enabled"` Enabled bool `yaml:"Enabled"`
Address string `yaml:"Address"` // Deprecated: please, use Addresses section instead. This field will be removed later.
Port uint16 `yaml:"Port"` Address *string `yaml:"Address,omitempty"`
// Deprecated: please, use Addresses section instead. This field will be removed later.
Port *uint16 `yaml:"Port,omitempty"`
// Addresses holds the list of bind addresses in the form of "address:port".
Addresses []string `yaml:"Addresses"`
} }
// FormatAddress returns the full service's address in the form of "address:port". // GetAddresses returns the set of unique (in terms of raw strings) pairs host:port
func (s BasicService) FormatAddress() string { // for the given basic service.
return net.JoinHostPort(s.Address, strconv.FormatUint(uint64(s.Port), 10)) func (s BasicService) GetAddresses() []string {
addrs := make([]string, len(s.Addresses), len(s.Addresses)+1)
copy(addrs, s.Addresses)
if s.Address != nil || s.Port != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
var (
addr string
port uint16
)
if s.Address != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
addr = *s.Address //nolint:staticcheck // SA1019: s.Address is deprecated
}
if s.Port != nil { //nolint:staticcheck // SA1019: s.Port is deprecated
port = *s.Port //nolint:staticcheck // SA1019: s.Port is deprecated
}
addrs = append(addrs, net.JoinHostPort(addr, strconv.FormatUint(uint64(port), 10)))
}
return addrs
} }

View file

@ -6,14 +6,24 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestBasicService_FormatAddress(t *testing.T) { func TestBasicService_GetAddresses(t *testing.T) {
for expected, tc := range map[string]BasicService{ addr := "1.2.3.4"
"localhost:10332": {Address: "localhost", Port: 10332}, port := uint16(1234)
"127.0.0.1:0": {Address: "127.0.0.1"}, s := BasicService{
":0": {}, Enabled: false,
} { Address: &addr,
t.Run(expected, func(t *testing.T) { Port: &port,
require.Equal(t, expected, tc.FormatAddress()) Addresses: []string{"1.2.3.4:1234", /* same as Address:Port */
}) "3.4.5.6:1234", "2.3.4.5", ":1235", "2.3.4.5:1234",
"3.4.5.6:1234" /* already in list */},
} }
require.Equal(t, []string{
"1.2.3.4:1234",
"3.4.5.6:1234",
"2.3.4.5",
":1235",
"2.3.4.5:1234",
"3.4.5.6:1234",
"1.2.3.4:1234",
}, s.GetAddresses())
} }

View file

@ -0,0 +1,24 @@
package config
import (
"testing"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
// TestRPC_UnmarshalBasicService is aimed to check that BasicService config of
// RPC service can be properly unmarshalled. This test may be removed after
// Address and Port config fields removal.
func TestRPC_UnmarshalBasicService(t *testing.T) {
data := `
Enabled: true
Port: 10332
MaxGasInvoke: 15
`
cfg := &RPC{}
err := yaml.Unmarshal([]byte(data), &cfg)
require.NoError(t, err)
require.True(t, cfg.Enabled)
require.Equal(t, uint16(10332), *cfg.Port)
}

View file

@ -3,31 +3,62 @@ package metrics
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"net"
"net/http" "net/http"
"github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config"
"go.uber.org/atomic"
"go.uber.org/zap" "go.uber.org/zap"
) )
// Service serves metrics. // Service serves metrics.
type Service struct { type Service struct {
*http.Server http []*http.Server
config config.BasicService config config.BasicService
log *zap.Logger log *zap.Logger
serviceType string serviceType string
started *atomic.Bool
}
// NewService configures logger and returns new service instance.
func NewService(name string, httpServers []*http.Server, cfg config.BasicService, log *zap.Logger) *Service {
return &Service{
http: httpServers,
config: cfg,
serviceType: name,
log: log.With(zap.String("service", name)),
started: atomic.NewBool(false),
}
} }
// Start runs http service with the exposed endpoint on the configured port. // Start runs http service with the exposed endpoint on the configured port.
func (ms *Service) Start() { func (ms *Service) Start() error {
if ms.config.Enabled { if ms.config.Enabled {
ms.log.Info("service is running", zap.String("endpoint", ms.Addr)) if !ms.started.CAS(false, true) {
err := ms.ListenAndServe() ms.log.Info("service already started")
if err != nil && !errors.Is(err, http.ErrServerClosed) { return nil
ms.log.Warn("service couldn't start on configured port") }
for _, srv := range ms.http {
ms.log.Info("starting service", zap.String("endpoint", srv.Addr))
ln, err := net.Listen("tcp", srv.Addr)
if err != nil {
return fmt.Errorf("failed to listen on %s: %w", srv.Addr, err)
}
srv.Addr = ln.Addr().String() // set Addr to the actual address
go func(s *http.Server) {
err = s.Serve(ln)
if !errors.Is(err, http.ErrServerClosed) {
ms.log.Error("failed to start service", zap.String("endpoint", s.Addr), zap.Error(err))
}
}(srv)
} }
} else { } else {
ms.log.Info("service hasn't started since it's disabled") ms.log.Info("service hasn't started since it's disabled")
} }
return nil
} }
// ShutDown stops the service. // ShutDown stops the service.
@ -35,9 +66,14 @@ func (ms *Service) ShutDown() {
if !ms.config.Enabled { if !ms.config.Enabled {
return return
} }
ms.log.Info("shutting down service", zap.String("endpoint", ms.Addr)) if !ms.started.CAS(true, false) {
err := ms.Shutdown(context.Background()) return
if err != nil { }
ms.log.Error("can't shut service down", zap.Error(err)) for _, srv := range ms.http {
ms.log.Info("shutting down service", zap.String("endpoint", srv.Addr))
err := srv.Shutdown(context.Background())
if err != nil {
ms.log.Error("can't shut service down", zap.String("endpoint", srv.Addr), zap.Error(err))
}
} }
} }

View file

@ -24,13 +24,13 @@ func NewPprofService(cfg config.BasicService, log *zap.Logger) *Service {
handler.HandleFunc("/debug/pprof/symbol", pprof.Symbol) handler.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
handler.HandleFunc("/debug/pprof/trace", pprof.Trace) handler.HandleFunc("/debug/pprof/trace", pprof.Trace)
return &Service{ addrs := cfg.GetAddresses()
Server: &http.Server{ srvs := make([]*http.Server, len(addrs))
Addr: cfg.FormatAddress(), for i, addr := range addrs {
srvs[i] = &http.Server{
Addr: addr,
Handler: handler, Handler: handler,
}, }
config: cfg,
serviceType: "Pprof",
log: log.With(zap.String("service", "Pprof")),
} }
return NewService("Pprof", srvs, cfg, log)
} }

View file

@ -17,13 +17,13 @@ func NewPrometheusService(cfg config.BasicService, log *zap.Logger) *Service {
return nil return nil
} }
return &Service{ addrs := cfg.GetAddresses()
Server: &http.Server{ srvs := make([]*http.Server, len(addrs))
Addr: cfg.FormatAddress(), for i, addr := range addrs {
Handler: promhttp.Handler(), srvs[i] = &http.Server{
}, Addr: addr,
config: cfg, Handler: promhttp.Handler(), // share metrics between multiple prometheus handlers
serviceType: "Prometheus", }
log: log.With(zap.String("service", "Prometheus")),
} }
return NewService("Prometheus", srvs, cfg, log)
} }

View file

@ -117,7 +117,9 @@ type (
// Server represents the JSON-RPC 2.0 server. // Server represents the JSON-RPC 2.0 server.
Server struct { Server struct {
*http.Server http []*http.Server
https []*http.Server
chain Ledger chain Ledger
config config.RPC config config.RPC
// wsReadLimit represents web-socket message limit for a receiving side. // wsReadLimit represents web-socket message limit for a receiving side.
@ -128,7 +130,6 @@ type (
coreServer *network.Server coreServer *network.Server
oracle *atomic.Value oracle *atomic.Value
log *zap.Logger log *zap.Logger
https *http.Server
shutdown chan struct{} shutdown chan struct{}
started *atomic.Bool started *atomic.Bool
errChan chan error errChan chan error
@ -254,14 +255,22 @@ var invalidBlockHeightError = func(index int, height int) *neorpc.Error {
// New creates a new Server struct. // New creates a new Server struct.
func New(chain Ledger, conf config.RPC, coreServer *network.Server, func New(chain Ledger, conf config.RPC, coreServer *network.Server,
orc OracleHandler, log *zap.Logger, errChan chan error) Server { orc OracleHandler, log *zap.Logger, errChan chan error) Server {
httpServer := &http.Server{ addrs := conf.GetAddresses()
Addr: conf.FormatAddress(), httpServers := make([]*http.Server, len(addrs))
for i, addr := range addrs {
httpServers[i] = &http.Server{
Addr: addr,
}
} }
var tlsServer *http.Server var tlsServers []*http.Server
if cfg := conf.TLSConfig; cfg.Enabled { if cfg := conf.TLSConfig; cfg.Enabled {
tlsServer = &http.Server{ addrs := cfg.GetAddresses()
Addr: cfg.FormatAddress(), tlsServers = make([]*http.Server, len(addrs))
for i, addr := range addrs {
tlsServers[i] = &http.Server{
Addr: addr,
}
} }
} }
@ -289,7 +298,9 @@ func New(chain Ledger, conf config.RPC, coreServer *network.Server,
wsOriginChecker = func(_ *http.Request) bool { return true } wsOriginChecker = func(_ *http.Request) bool { return true }
} }
return Server{ return Server{
Server: httpServer, http: httpServers,
https: tlsServers,
chain: chain, chain: chain,
config: conf, config: conf,
wsReadLimit: int64(protoCfg.MaxBlockSize*4)/3 + 1024, // Enough for Base64-encoded content of `submitblock` and `submitp2pnotaryrequest`. wsReadLimit: int64(protoCfg.MaxBlockSize*4)/3 + 1024, // Enough for Base64-encoded content of `submitblock` and `submitp2pnotaryrequest`.
@ -299,7 +310,6 @@ func New(chain Ledger, conf config.RPC, coreServer *network.Server,
coreServer: coreServer, coreServer: coreServer,
log: log, log: log,
oracle: oracleWrapped, oracle: oracleWrapped,
https: tlsServer,
shutdown: make(chan struct{}), shutdown: make(chan struct{}),
started: atomic.NewBool(false), started: atomic.NewBool(false),
errChan: errChan, errChan: errChan,
@ -333,40 +343,48 @@ func (s *Server) Start() {
s.log.Info("RPC server already started") s.log.Info("RPC server already started")
return return
} }
s.Handler = http.HandlerFunc(s.handleHTTPRequest) for _, srv := range s.http {
s.log.Info("starting rpc-server", zap.String("endpoint", s.Addr)) srv.Handler = http.HandlerFunc(s.handleHTTPRequest)
s.log.Info("starting rpc-server", zap.String("endpoint", srv.Addr))
ln, err := net.Listen("tcp", srv.Addr)
if err != nil {
s.errChan <- fmt.Errorf("failed to listen on %s: %w", srv.Addr, err)
return
}
srv.Addr = ln.Addr().String() // set Addr to the actual address
go func(server *http.Server) {
err = server.Serve(ln)
if !errors.Is(err, http.ErrServerClosed) {
s.log.Error("failed to start RPC server", zap.Error(err))
s.errChan <- err
}
}(srv)
}
go s.handleSubEvents() go s.handleSubEvents()
if cfg := s.config.TLSConfig; cfg.Enabled { if cfg := s.config.TLSConfig; cfg.Enabled {
s.https.Handler = http.HandlerFunc(s.handleHTTPRequest) for _, srv := range s.https {
s.log.Info("starting rpc-server (https)", zap.String("endpoint", s.https.Addr)) srv.Handler = http.HandlerFunc(s.handleHTTPRequest)
go func() { s.log.Info("starting rpc-server (https)", zap.String("endpoint", srv.Addr))
ln, err := net.Listen("tcp", s.https.Addr)
ln, err := net.Listen("tcp", srv.Addr)
if err != nil { if err != nil {
s.errChan <- err s.errChan <- err
return return
} }
s.https.Addr = ln.Addr().String() srv.Addr = ln.Addr().String()
err = s.https.ServeTLS(ln, cfg.CertFile, cfg.KeyFile)
if !errors.Is(err, http.ErrServerClosed) { go func(srv *http.Server) {
s.log.Error("failed to start TLS RPC server", zap.Error(err)) err = srv.ServeTLS(ln, cfg.CertFile, cfg.KeyFile)
s.errChan <- err if !errors.Is(err, http.ErrServerClosed) {
} s.log.Error("failed to start TLS RPC server",
}() zap.String("endpoint", srv.Addr), zap.Error(err))
} s.errChan <- err
ln, err := net.Listen("tcp", s.Addr) }
if err != nil { }(srv)
s.errChan <- err
return
}
s.Addr = ln.Addr().String() // set Addr to the actual address
go func() {
err = s.Serve(ln)
if !errors.Is(err, http.ErrServerClosed) {
s.log.Error("failed to start RPC server", zap.Error(err))
s.errChan <- err
} }
}() }
} }
// Shutdown stops the RPC server if it's running. It can only be called once, // Shutdown stops the RPC server if it's running. It can only be called once,
@ -381,17 +399,23 @@ func (s *Server) Shutdown() {
close(s.shutdown) close(s.shutdown)
if s.config.TLSConfig.Enabled { if s.config.TLSConfig.Enabled {
s.log.Info("shutting down RPC server (https)", zap.String("endpoint", s.https.Addr)) for _, srv := range s.https {
err := s.https.Shutdown(context.Background()) s.log.Info("shutting down RPC server (https)", zap.String("endpoint", srv.Addr))
if err != nil { err := srv.Shutdown(context.Background())
s.log.Warn("error during RPC (https) server shutdown", zap.Error(err)) if err != nil {
s.log.Warn("error during RPC (https) server shutdown",
zap.String("endpoint", srv.Addr), zap.Error(err))
}
} }
} }
s.log.Info("shutting down RPC server", zap.String("endpoint", s.Addr)) for _, srv := range s.http {
err := s.Server.Shutdown(context.Background()) s.log.Info("shutting down RPC server", zap.String("endpoint", srv.Addr))
if err != nil { err := srv.Shutdown(context.Background())
s.log.Warn("error during RPC (http) server shutdown", zap.Error(err)) if err != nil {
s.log.Warn("error during RPC (http) server shutdown",
zap.String("endpoint", srv.Addr), zap.Error(err))
}
} }
// Perform sessions finalisation. // Perform sessions finalisation.
@ -2790,3 +2814,13 @@ func escapeForLog(in string) string {
return c return c
}, in) }, in)
} }
// Addresses returns the list of addresses RPC server is listening to in the form of
// address:port.
func (s *Server) Addresses() []string {
res := make([]string, len(s.http))
for i, srv := range s.http {
res[i] = srv.Addr
}
return res
}