forked from nspcc-dev/neofs-testcases
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: additional smart contracts deploy and update (nspcc-dev#643)
- Loading branch information
Showing
10 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import os | ||
|
||
import allure | ||
import pytest | ||
from cluster import Cluster | ||
from common import NEOFS_ADM_CONFIG_PATH, NEOFS_ADM_EXEC, NEOGO_EXECUTABLE | ||
from neofs_testlib.cli import NeofsAdm, NeoGo | ||
from neofs_testlib.shell import Shell | ||
|
||
from steps.cluster_test_base import ClusterTestBase | ||
|
||
|
||
@pytest.mark.additional_contracts | ||
class TestContract(ClusterTestBase): | ||
@allure.title("Test operations with external smart contracts") | ||
def test_contract(self, datadir, client_shell: Shell, cluster: Cluster): | ||
neogo = NeoGo(client_shell, neo_go_exec_path=NEOGO_EXECUTABLE) | ||
with allure.step("Compile new contract"): | ||
neogo.contract.contract_compile( | ||
i=os.path.join(datadir, "deploy"), | ||
out=os.path.join(datadir, "deploy", "testctr_contract.nef"), | ||
manifest=os.path.join(datadir, "deploy", "config.json"), | ||
config=os.path.join(datadir, "deploy", "neo-go.yml"), | ||
) | ||
|
||
neofsadm = NeofsAdm( | ||
shell=client_shell, | ||
neofs_adm_exec_path=NEOFS_ADM_EXEC, | ||
config_file=NEOFS_ADM_CONFIG_PATH, | ||
) | ||
|
||
with allure.step("Try to deploy contract with wrong arguments"): | ||
with pytest.raises(RuntimeError, match=".*deploy has failed.*"): | ||
neofsadm.morph.deploy( | ||
rpc_endpoint=cluster.morph_chain_nodes[0].get_endpoint(), | ||
alphabet_wallets="/".join( | ||
cluster.ir_nodes[0].get_wallet_path().split("/")[:-1] | ||
), | ||
domain="myzone", | ||
contract=os.path.join(datadir, "deploy"), | ||
post_data="string:shouldFail", | ||
) | ||
|
||
with allure.step("Try to deploy contract with valid arguments"): | ||
neofsadm.morph.deploy( | ||
rpc_endpoint=cluster.morph_chain_nodes[0].get_endpoint(), | ||
alphabet_wallets="/".join(cluster.ir_nodes[0].get_wallet_path().split("/")[:-1]), | ||
domain="myzone", | ||
contract=os.path.join(datadir, "deploy"), | ||
post_data="string:ok", | ||
) | ||
|
||
with allure.step("Try to update deployed contract"): | ||
with allure.step("Compile new contract"): | ||
neogo.contract.contract_compile( | ||
i=os.path.join(datadir, "update"), | ||
out=os.path.join(datadir, "update", "testctr_contract.nef"), | ||
manifest=os.path.join(datadir, "update", "config.json"), | ||
config=os.path.join(datadir, "update", "neo-go.yml"), | ||
) | ||
|
||
with allure.step("Try to deploy updated contract with wrong arguments"): | ||
with pytest.raises(RuntimeError, match=".*update has failed.*"): | ||
neofsadm.morph.deploy( | ||
rpc_endpoint=cluster.morph_chain_nodes[0].get_endpoint(), | ||
alphabet_wallets="/".join( | ||
cluster.ir_nodes[0].get_wallet_path().split("/")[:-1] | ||
), | ||
domain="myzone", | ||
update=True, | ||
contract=os.path.join(datadir, "update"), | ||
post_data="string:shouldFail", | ||
) | ||
|
||
with allure.step("Try to deploy updated contract with valid arguments"): | ||
neofsadm.morph.deploy( | ||
rpc_endpoint=cluster.morph_chain_nodes[0].get_endpoint(), | ||
alphabet_wallets="/".join( | ||
cluster.ir_nodes[0].get_wallet_path().split("/")[:-1] | ||
), | ||
domain="myzone", | ||
update=True, | ||
contract=os.path.join(datadir, "update"), | ||
post_data="string:ok", | ||
) | ||
|
||
hashes = neofsadm.morph.dump_hashes( | ||
rpc_endpoint=cluster.morph_chain_nodes[0].get_endpoint(), | ||
domain="myzone", | ||
) | ||
assert hashes != "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module testctr | ||
|
||
go 1.18 | ||
|
||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220728091153-a5afa875712b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220728091153-a5afa875712b h1://k5FEn2ImNwEwUXK34sqM+6MUI9fKX7vFBJji3u0CU= | ||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220728091153-a5afa875712b/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y= |
26 changes: 26 additions & 0 deletions
26
pytest_tests/testsuites/contract/test_contract/deploy/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package testdata | ||
|
||
import ( | ||
"github.com/nspcc-dev/neo-go/pkg/interop" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/contract" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" | ||
) | ||
|
||
func _deploy(data interface{}, isUpdate bool) { | ||
if !isUpdate && data.(string) == "shouldFail" { | ||
panic("deploy has failed") | ||
} | ||
} | ||
|
||
// GetThree is a simple function which does nothing. | ||
func GetThree() int { | ||
return 3 | ||
} | ||
|
||
// Update allows to update this contract. | ||
func Update(nef, manifest []byte, data interface{}) { | ||
contract.Call(interop.Hash160(management.Hash), "update", | ||
contract.All, nef, manifest, data) | ||
runtime.Log("test contract was updated") | ||
} |
6 changes: 6 additions & 0 deletions
6
pytest_tests/testsuites/contract/test_contract/deploy/neo-go.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: testctr | ||
sourceurl: http://example.com/ | ||
safemethods: [] | ||
supportedstandards: [] | ||
permissions: | ||
- methods: '*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module testctr | ||
|
||
go 1.18 |
12 changes: 12 additions & 0 deletions
12
pytest_tests/testsuites/contract/test_contract/update/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package testdata | ||
|
||
func _deploy(data interface{}, isUpdate bool) { | ||
if isUpdate && data.(string) == "shouldFail" { | ||
panic("update has failed") | ||
} | ||
} | ||
|
||
// GetThree is a simple function which does nothing. | ||
func GetThree() int { | ||
return 42 | ||
} |
6 changes: 6 additions & 0 deletions
6
pytest_tests/testsuites/contract/test_contract/update/neo-go.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: testctr | ||
sourceurl: http://example.com/ | ||
safemethods: [] | ||
supportedstandards: [] | ||
permissions: | ||
- methods: '*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters