From 820269fd414a5bbc9df9f77a768db70d2288267e Mon Sep 17 00:00:00 2001 From: Otniel Nicola Date: Thu, 12 Dec 2024 11:35:59 +0200 Subject: [PATCH] Apply changes after review --- .idea/codeStyles/Project.xml | 41 ++ .idea/codeStyles/codeStyleConfig.xml | 5 + .../neo/grantshares/GrantSharesGov.java | 4 - .../neo/grantshares/GrantSharesTreasury.java | 4 - .../grantshares/GovernanceMembersTest.java | 50 +- .../grantshares/GovernanceParametersTest.java | 60 +- .../neo/grantshares/GrantSharesGovTest.java | 516 +++++++++--------- .../grantshares/GrantSharesTreasuryTest.java | 138 +++-- .../grantshares/ProposalExecutionsTest.java | 60 +- .../neo/grantshares/TreasuryMultiSigTest.java | 32 +- .../neo/grantshares/util/TestHelper.java | 209 ++++--- 11 files changed, 609 insertions(+), 510 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..7ac15c5 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,41 @@ + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/main/java/com/axlabs/neo/grantshares/GrantSharesGov.java b/src/main/java/com/axlabs/neo/grantshares/GrantSharesGov.java index 39a75b8..c8fd6b9 100644 --- a/src/main/java/com/axlabs/neo/grantshares/GrantSharesGov.java +++ b/src/main/java/com/axlabs/neo/grantshares/GrantSharesGov.java @@ -590,8 +590,4 @@ public static void abortIfPaused() { Helper.abort("abortIfPaused" + ": " + "Contract is paused"); } } - - private static void abortWithMessage(String method, String msg) { - Helper.abort(method + ": " + msg); - } } diff --git a/src/main/java/com/axlabs/neo/grantshares/GrantSharesTreasury.java b/src/main/java/com/axlabs/neo/grantshares/GrantSharesTreasury.java index d5bb325..661ac91 100644 --- a/src/main/java/com/axlabs/neo/grantshares/GrantSharesTreasury.java +++ b/src/main/java/com/axlabs/neo/grantshares/GrantSharesTreasury.java @@ -487,8 +487,4 @@ private static void abortIfCallerIsNotOwner() { private static void abortIfPaused() { if (isPaused()) Helper.abort("abortIfCallerIsNotOwner" + ": " + "Contract is paused"); } - - private static void abortWithMessage(String method, String msg) { - Helper.abort(method + ": " + msg); - } } diff --git a/src/test/java/com/axlabs/neo/grantshares/GovernanceMembersTest.java b/src/test/java/com/axlabs/neo/grantshares/GovernanceMembersTest.java index 59d0291..b1fda0d 100644 --- a/src/test/java/com/axlabs/neo/grantshares/GovernanceMembersTest.java +++ b/src/test/java/com/axlabs/neo/grantshares/GovernanceMembersTest.java @@ -27,17 +27,36 @@ import java.util.List; import java.util.stream.Collectors; -import static com.axlabs.neo.grantshares.util.TestHelper.*; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.MEMBER_ADDED; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.MEMBER_REMOVED; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.PROPOSAL_EXECUTED; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.ADD_MEMBER; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.CALC_MEMBER_MULTI_SIG_ACC; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.GET_MEMBERS; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.REMOVE_MEMBER; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.ALICE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.BOB; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.CHARLIE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.DENISE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.PHASE_LENGTH; +import static com.axlabs.neo.grantshares.util.TestHelper.createAndEndorseProposal; +import static com.axlabs.neo.grantshares.util.TestHelper.createMultiSigAccount; +import static com.axlabs.neo.grantshares.util.TestHelper.prepareDeployParameter; +import static com.axlabs.neo.grantshares.util.TestHelper.voteForProposal; import static io.neow3j.types.ContractParameter.array; -import static io.neow3j.types.ContractParameter.*; +import static io.neow3j.types.ContractParameter.hash160; +import static io.neow3j.types.ContractParameter.publicKey; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @ContractTest(contracts = GrantSharesGov.class, blockTime = 1, configFile = "default.neo-express", - batchFile = "setup.batch") + batchFile = "setup.batch") @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class GovernanceMembersTest { @@ -71,8 +90,9 @@ public static void setUp() throws Throwable { //region ADD MEMBER @Test - public void fail_calling_add_member_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(ADD_MEMBER, hash160(bob)).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_add_member_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(ADD_MEMBER, hash160(bob)).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Method only callable by the contract itself")); } @@ -99,7 +119,8 @@ public void execute_add_member() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Hash256 tx = gov.execute(id).signers(AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); + Hash256 tx = gov.execute(id).signers( + AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); NeoApplicationLog.Execution execution = neow3j.getApplicationLog(tx).send() @@ -140,7 +161,8 @@ public void fail_execute_add_member_with_already_member() throws Throwable { voteForProposal(gov, neow3j, id, charlie); // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(charlie)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Already a member")); } @@ -171,8 +193,10 @@ public void fail_execute_add_member_with_invalid_public_key() throws Throwable { //region REMOVE MEMBER @Test - public void fail_calling_remove_member_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(REMOVE_MEMBER, hash160(bob)).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_remove_member_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(REMOVE_MEMBER, hash160(bob)).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Method only callable by the contract itself")); } @@ -198,7 +222,8 @@ public void execute_remove_member() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Hash256 tx = gov.execute(id).signers(AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); + Hash256 tx = gov.execute(id).signers( + AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); NeoApplicationLog.Execution execution = neow3j.getApplicationLog(tx).send() @@ -237,7 +262,8 @@ public void fail_execute_remove_member_with_non_member() throws Throwable { voteForProposal(gov, neow3j, id, charlie); // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(charlie)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Not a member")); } diff --git a/src/test/java/com/axlabs/neo/grantshares/GovernanceParametersTest.java b/src/test/java/com/axlabs/neo/grantshares/GovernanceParametersTest.java index 9d9288f..098ea61 100644 --- a/src/test/java/com/axlabs/neo/grantshares/GovernanceParametersTest.java +++ b/src/test/java/com/axlabs/neo/grantshares/GovernanceParametersTest.java @@ -24,23 +24,23 @@ import java.util.List; import java.util.Map; -import static com.axlabs.neo.grantshares.util.TestHelper.ALICE; -import static com.axlabs.neo.grantshares.util.TestHelper.BOB; -import static com.axlabs.neo.grantshares.util.TestHelper.CHANGE_PARAM; -import static com.axlabs.neo.grantshares.util.TestHelper.CHARLIE; -import static com.axlabs.neo.grantshares.util.TestHelper.EXPIRATION_LENGTH_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_ACCEPTANCE_RATE; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_ACCEPTANCE_RATE_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_QUORUM; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_QUORUM_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.MULTI_SIG_THRESHOLD_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.MULTI_SIG_THRESHOLD_RATIO; -import static com.axlabs.neo.grantshares.util.TestHelper.PARAMETER_CHANGED; -import static com.axlabs.neo.grantshares.util.TestHelper.PHASE_LENGTH; -import static com.axlabs.neo.grantshares.util.TestHelper.PROPOSAL_EXECUTED; -import static com.axlabs.neo.grantshares.util.TestHelper.REVIEW_LENGTH_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.TIMELOCK_LENGTH_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.VOTING_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.PARAMETER_CHANGED; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.PROPOSAL_EXECUTED; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.CHANGE_PARAM; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.ALICE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.BOB; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.CHARLIE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.EXPIRATION_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.MIN_ACCEPTANCE_RATE_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.MIN_QUORUM_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.MULTI_SIG_THRESHOLD_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.REVIEW_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.TIMELOCK_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.VOTING_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.MIN_ACCEPTANCE_RATE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.MIN_QUORUM; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.MULTI_SIG_THRESHOLD_RATIO; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.PHASE_LENGTH; import static com.axlabs.neo.grantshares.util.TestHelper.createAndEndorseProposal; import static com.axlabs.neo.grantshares.util.TestHelper.prepareDeployParameter; import static com.axlabs.neo.grantshares.util.TestHelper.voteForProposal; @@ -54,7 +54,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @ContractTest(contracts = GrantSharesGov.class, blockTime = 1, configFile = "default.neo-express", - batchFile = "setup.batch") + batchFile = "setup.batch") public class GovernanceParametersTest { @RegisterExtension @@ -138,8 +138,10 @@ public void execute_change_parameter() throws Throwable { } @Test - public void fail_calling_change_parameter_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(CHANGE_PARAM, string(REVIEW_LENGTH_KEY), integer(100)).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_change_parameter_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(CHANGE_PARAM, string(REVIEW_LENGTH_KEY), integer(100)).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Method only callable by the contract itself")); } @@ -158,7 +160,8 @@ public void fail_changing_unknown_parameter() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Unknown parameter")); } @@ -175,7 +178,8 @@ public void fail_changing_voting_length_to_negative_value() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Invalid parameter value")); assertThat(gov.getParameter(VOTING_LENGTH_KEY).getInteger().intValue(), is(PHASE_LENGTH * 1000)); } @@ -193,7 +197,8 @@ public void fail_changing_min_acceptance_rate_to_negative_value() throws Throwab // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Invalid parameter value")); assertThat(gov.getParameter(MIN_ACCEPTANCE_RATE_KEY).getInteger().intValue(), is(MIN_ACCEPTANCE_RATE)); } @@ -211,7 +216,8 @@ public void fail_changing_min_acceptance_rate_to_more_than_hundred() throws Thro // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Invalid parameter value")); assertThat(gov.getParameter(MIN_ACCEPTANCE_RATE_KEY).getInteger().intValue(), is(MIN_ACCEPTANCE_RATE)); } @@ -229,7 +235,8 @@ public void fail_changing_multisig_threshold_to_zero() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Invalid parameter value")); assertThat(gov.getParameter(MULTI_SIG_THRESHOLD_KEY).getInteger().intValue(), is(MULTI_SIG_THRESHOLD_RATIO)); } @@ -247,7 +254,8 @@ public void fail_changing_multisig_threshold_to_more_than_hundred() throws Throw // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Invalid parameter value")); assertThat(gov.getParameter(MULTI_SIG_THRESHOLD_KEY).getInteger().intValue(), is(MULTI_SIG_THRESHOLD_RATIO)); } diff --git a/src/test/java/com/axlabs/neo/grantshares/GrantSharesGovTest.java b/src/test/java/com/axlabs/neo/grantshares/GrantSharesGovTest.java index fd5793f..ba8b1d7 100644 --- a/src/test/java/com/axlabs/neo/grantshares/GrantSharesGovTest.java +++ b/src/test/java/com/axlabs/neo/grantshares/GrantSharesGovTest.java @@ -9,7 +9,11 @@ import io.neow3j.contract.NefFile; import io.neow3j.contract.NeoToken; import io.neow3j.protocol.Neow3j; -import io.neow3j.protocol.core.response.*; +import io.neow3j.protocol.core.response.ContractManifest; +import io.neow3j.protocol.core.response.InvocationResult; +import io.neow3j.protocol.core.response.NeoApplicationLog; +import io.neow3j.protocol.core.response.NeoInvokeFunction; +import io.neow3j.protocol.core.response.Notification; import io.neow3j.protocol.core.stackitem.StackItem; import io.neow3j.test.ContractTest; import io.neow3j.test.ContractTestExtension; @@ -40,29 +44,17 @@ import java.util.Collections; import java.util.List; -import static com.axlabs.neo.grantshares.util.TestHelper.ADD_MEMBER; -import static com.axlabs.neo.grantshares.util.TestHelper.ALICE; -import static com.axlabs.neo.grantshares.util.TestHelper.BOB; -import static com.axlabs.neo.grantshares.util.TestHelper.CHANGE_PARAM; -import static com.axlabs.neo.grantshares.util.TestHelper.CHARLIE; -import static com.axlabs.neo.grantshares.util.TestHelper.CREATE; -import static com.axlabs.neo.grantshares.util.TestHelper.ENDORSE; -import static com.axlabs.neo.grantshares.util.TestHelper.EXECUTE; -import static com.axlabs.neo.grantshares.util.TestHelper.GET_PROPOSAL; -import static com.axlabs.neo.grantshares.util.TestHelper.GET_PROPOSAL_COUNT; -import static com.axlabs.neo.grantshares.util.TestHelper.IS_PAUSED; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_ACCEPTANCE_RATE; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_ACCEPTANCE_RATE_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_QUORUM; -import static com.axlabs.neo.grantshares.util.TestHelper.PAUSE; -import static com.axlabs.neo.grantshares.util.TestHelper.PHASE_LENGTH; -import static com.axlabs.neo.grantshares.util.TestHelper.PROPOSAL_CREATED; -import static com.axlabs.neo.grantshares.util.TestHelper.PROPOSAL_ENDORSED; -import static com.axlabs.neo.grantshares.util.TestHelper.REMOVE_MEMBER; -import static com.axlabs.neo.grantshares.util.TestHelper.UNPAUSE; -import static com.axlabs.neo.grantshares.util.TestHelper.UPDATE_CONTRACT; -import static com.axlabs.neo.grantshares.util.TestHelper.VOTE; -import static com.axlabs.neo.grantshares.util.TestHelper.VOTED; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.PROPOSAL_CREATED; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.PROPOSAL_ENDORSED; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.VOTED; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.*; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.ALICE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.BOB; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.CHARLIE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.MIN_ACCEPTANCE_RATE_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.MIN_ACCEPTANCE_RATE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.MIN_QUORUM; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.PHASE_LENGTH; import static com.axlabs.neo.grantshares.util.TestHelper.createAndEndorseProposal; import static com.axlabs.neo.grantshares.util.TestHelper.createMultiSigAccount; import static com.axlabs.neo.grantshares.util.TestHelper.createSimpleProposal; @@ -83,18 +75,19 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; @ContractTest(contracts = GrantSharesGov.class, blockTime = 1, configFile = "default.neo-express", - batchFile = "setup.batch") + batchFile = "setup.batch") @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class GrantSharesGovTest { @RegisterExtension private static final ContractTestExtension ext = new ContractTestExtension(); private final static Path TESTCONTRACT_NEF_FILE = Paths.get("TestContract.nef"); - private final static Path TESTCONTRACT_MANIFEST_FILE = - Paths.get("TestGrantSharesGov.manifest.json"); + private final static Path TESTCONTRACT_MANIFEST_FILE = Paths.get("TestGrantSharesGov.manifest.json"); private static Neow3j neow3j; private static GrantSharesGovContract gov; private static Account alice; // Set to be a DAO member. @@ -105,8 +98,7 @@ public class GrantSharesGovTest { @DeployConfig(GrantSharesGov.class) public static DeployConfiguration deployConfig() throws Exception { DeployConfiguration config = new DeployConfiguration(); - config.setDeployParam(prepareDeployParameter( - ext.getAccount(ALICE), ext.getAccount(CHARLIE))); + config.setDeployParam(prepareDeployParameter(ext.getAccount(ALICE), ext.getAccount(CHARLIE))); return config; } @@ -119,15 +111,12 @@ public static void setUp() throws Throwable { charlie = ext.getAccount(CHARLIE); Hash256 creationTx = gov.invokeFunction(CREATE, hash160(alice.getScriptHash()), - array(array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - integer(CallFlags.ALL.getValue()))), - string("default_proposal"), - integer(-1)) - .signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + array(array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + integer(CallFlags.ALL.getValue()))), string("default_proposal"), integer(-1)).signers( + AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - defaultProposalId = neow3j.getApplicationLog(creationTx).send().getApplicationLog() - .getExecutions().get(0).getStack().get(0).getInteger().intValue(); + defaultProposalId = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get( + 0).getStack().get(0).getInteger().intValue(); } @Test @@ -139,23 +128,19 @@ public void succeed_creating_and_retrieving_proposal() throws Throwable { Hash160 targetParam1 = gov.getScriptHash(); Hash160 targetParam2 = alice.getScriptHash(); int targetParam3 = 1; - ContractParameter intent = array(targetContract, targetMethod, - array(targetParam1, targetParam2, targetParam3), integer(CallFlags.ALL.getValue())); + ContractParameter intent = array(targetContract, targetMethod, array(targetParam1, targetParam2, targetParam3), + integer(CallFlags.ALL.getValue())); String offchainUri = "offchainUri of the proposal"; - Hash256 proposalCreationTx = gov.invokeFunction(CREATE, - hash160(alice.getScriptHash()), - array(intent), - string(offchainUri), - integer(-1)) // no linked proposal - .signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 proposalCreationTx = gov.invokeFunction(CREATE, hash160(alice.getScriptHash()), array(intent), + string(offchainUri), integer(-1)) // no linked proposal + .signers(AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(proposalCreationTx, neow3j); - int id = neow3j.getApplicationLog(proposalCreationTx).send() - .getApplicationLog().getExecutions().get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(proposalCreationTx).send().getApplicationLog().getExecutions().get( + 0).getStack().get(0).getInteger().intValue(); // 2. Test correct setup of the created proposal. - NeoInvokeFunction r = gov.callInvokeFunction(GET_PROPOSAL, Collections.singletonList(integer(id))); + NeoInvokeFunction r = gov.callInvokeFunction(GET_PROPOSAL, asList(integer(id))); ProposalStruct p = new ProposalStruct(r.getInvocationResult().getStack().get(0).getList()); assertThat(p.id, is(id)); assertThat(p.proposer, is(alice.getScriptHash())); @@ -173,9 +158,8 @@ public void succeed_creating_and_retrieving_proposal() throws Throwable { assertThat(p.intents.get(0).params.get(2).getInteger().intValue(), is(targetParam3)); // 3. Test CreateProposal event values - List ntfs = - neow3j.getApplicationLog(proposalCreationTx).send().getApplicationLog() - .getExecutions().get(0).getNotifications(); + List ntfs = neow3j.getApplicationLog( + proposalCreationTx).send().getApplicationLog().getExecutions().get(0).getNotifications(); Notification ntf = ntfs.get(0); assertThat(ntf.getEventName(), is(PROPOSAL_CREATED)); @@ -188,40 +172,50 @@ public void succeed_creating_and_retrieving_proposal() throws Throwable { @Test @Order(0) - public void fail_creating_with_missing_linked_proposal() throws Throwable { + public void fail_creating_with_missing_linked_proposal() { ContractParameter intent = array(NeoToken.SCRIPT_HASH, "transfer", array(gov.getScriptHash(), alice.getScriptHash(), 1)); String offchainUri = "fail_creating_with_missing_linked_proposal"; - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.createProposal(alice.getScriptHash(), offchainUri, 1000, intent).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.createProposal(alice.getScriptHash(), offchainUri, 1000, intent).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Linked proposal doesn't exist")); } @Test @Order(0) - public void fail_creating_with_bad_quorum() throws Throwable { + public void fail_creating_with_bad_quorum() { ContractParameter intent = array(NeoToken.SCRIPT_HASH, "transfer", array(gov.getScriptHash(), alice.getScriptHash(), 1)); String offchainUri = "fail_creating_with_bad_quorum"; - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, MIN_ACCEPTANCE_RATE, MIN_QUORUM - 1, intent).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, MIN_ACCEPTANCE_RATE, MIN_QUORUM - 1, + intent).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid quorum")); - e = assertThrows(TransactionConfigurationException.class, () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, MIN_ACCEPTANCE_RATE, 101, intent).signers(AccountSigner.calledByEntry(alice)).sign()); + e = assertThrows(TransactionConfigurationException.class, + () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, MIN_ACCEPTANCE_RATE, 101, + intent).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid quorum")); } @Test @Order(0) - public void fail_creating_with_bad_acceptance_rate() throws Throwable { + public void fail_creating_with_bad_acceptance_rate() { ContractParameter intent = array(NeoToken.SCRIPT_HASH, "transfer", array(gov.getScriptHash(), alice.getScriptHash(), 1)); String offchainUri = "fail_creating_with_bad_acceptance_rate"; - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, MIN_ACCEPTANCE_RATE - 1, MIN_QUORUM, intent).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, MIN_ACCEPTANCE_RATE - 1, MIN_QUORUM, + intent).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid acceptance rate")); - e = assertThrows(TransactionConfigurationException.class, () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, 101, MIN_QUORUM, intent).signers(AccountSigner.calledByEntry(alice)).sign()); + e = assertThrows(TransactionConfigurationException.class, + () -> gov.createProposal(alice.getScriptHash(), offchainUri, -1, 101, MIN_QUORUM, intent).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid acceptance rate")); } @@ -231,8 +225,8 @@ public void succeed_endorsing_with_member() throws Throwable { // 1. Create a proposal Hash256 creationTx = createSimpleProposal(gov, alice, "succeed_endorsing_with_member"); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - int id = neow3j.getApplicationLog(creationTx).send() - .getApplicationLog().getExecutions().get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); // 2. Test that proposal endorser and phases have not yet been setup. ProposalStruct p = gov.getProposal(id); @@ -243,10 +237,8 @@ public void succeed_endorsing_with_member() throws Throwable { assertThat(p.expiration, is(greaterThan(BigInteger.ZERO))); // 3. Endorse - Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), - hash160(alice.getScriptHash())) - .signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), hash160(alice.getScriptHash())).signers( + AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(endorseTx, neow3j); // 4. Test the right setup of the proposal phases @@ -267,8 +259,8 @@ public void succeed_endorsing_with_member() throws Throwable { assertThat(p.abstain, is(0)); // 6. Test emitted "endorsed" event - Notification ntf = neow3j.getApplicationLog(endorseTx).send() - .getApplicationLog().getExecutions().get(0).getNotifications().get(0); + Notification ntf = neow3j.getApplicationLog(endorseTx).send().getApplicationLog().getExecutions().get( + 0).getNotifications().get(0); assertThat(ntf.getEventName(), is(PROPOSAL_ENDORSED)); List state = ntf.getState().getList(); assertThat(state.get(0).getInteger().intValue(), is(id)); @@ -277,15 +269,19 @@ public void succeed_endorsing_with_member() throws Throwable { @Test @Order(0) - public void fail_endorsing_with_non_member() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.endorseProposal(defaultProposalId, bob.getScriptHash()).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_endorsing_with_non_member() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.endorseProposal(defaultProposalId, bob.getScriptHash()).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @Test @Order(0) - public void fail_endorsing_with_member_but_wrong_signer() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.endorseProposal(defaultProposalId, alice.getScriptHash()).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_endorsing_with_member_but_wrong_signer() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.endorseProposal(defaultProposalId, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @@ -295,23 +291,27 @@ public void fail_endorsing_already_endorsed_proposal() throws Throwable { // 1. Create a proposal Hash256 creationTx = createSimpleProposal(gov, alice, "fail_endorsing_already_endorsed_proposal"); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack() - .get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); // 2. Endorse - Hash256 endorseTx = gov.endorseProposal(id, alice.getScriptHash()).signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 endorseTx = gov.endorseProposal(id, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(endorseTx, neow3j); // 3. Endorse again - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.endorseProposal(id, alice.getScriptHash()).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.endorseProposal(id, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Proposal already endorsed")); } @Test @Order(0) - public void fail_endorsing_non_existent_proposal() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.endorseProposal(1000, alice.getScriptHash()).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_endorsing_non_existent_proposal() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.endorseProposal(1000, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Proposal doesn't exist")); } @@ -320,11 +320,13 @@ public void fail_endorsing_non_existent_proposal() throws Throwable { public void fail_endorsing_expired_proposal() throws Throwable { Hash256 creationTx = createSimpleProposal(gov, bob, "fail_endorsing_expired_proposal"); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - int id = neow3j.getApplicationLog(creationTx).send() - .getApplicationLog().getExecutions().get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); ext.fastForwardOneBlock(PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.endorseProposal(id, alice.getScriptHash()).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.endorseProposal(id, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Proposal expired")); } @@ -334,24 +336,20 @@ public void succeed_voting() throws Throwable { // 1. Create proposal Hash256 creationTx = createSimpleProposal(gov, bob, "succeed_voting"); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - int id = neow3j.getApplicationLog(creationTx).send() - .getApplicationLog().getExecutions().get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); // 2. Endorse - Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), - hash160(alice.getScriptHash())) - .signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), hash160(alice.getScriptHash())).signers( + AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(endorseTx, neow3j); // 3. Wait till review phase ends. ext.fastForwardOneBlock(PHASE_LENGTH); // 4. Vote - Hash256 voteTx = gov.invokeFunction(VOTE, integer(id), integer(-1), - hash160(charlie.getScriptHash())) - .signers(AccountSigner.calledByEntry(charlie)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 voteTx = gov.invokeFunction(VOTE, integer(id), integer(-1), hash160(charlie.getScriptHash())).signers( + AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(voteTx, neow3j); // 5. Test the right setting of the votes @@ -363,8 +361,8 @@ public void succeed_voting() throws Throwable { assertThat(proposal.voters.get(charlie.getAddress()), is(-1)); // 6. Test the emitted vote event - Notification ntf = neow3j.getApplicationLog(voteTx).send() - .getApplicationLog().getExecutions().get(0).getNotifications().get(0); + Notification ntf = neow3j.getApplicationLog(voteTx).send().getApplicationLog().getExecutions().get( + 0).getNotifications().get(0); assertThat(ntf.getEventName(), is(VOTED)); List state = ntf.getState().getList(); assertThat(state.get(0).getInteger().intValue(), is(id)); @@ -377,25 +375,25 @@ public void succeed_voting() throws Throwable { public void fail_voting_in_review_and_queued_phase() throws Throwable { Hash256 creationTx = createSimpleProposal(gov, bob, "fail_voting_in_review_and_queued_phase"); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions() - .get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); // 2. Endorse - Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), - hash160(alice.getScriptHash())) - .signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), hash160(alice.getScriptHash())).signers( + AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(endorseTx, neow3j); // 3. Vote in review phase - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(id, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(id, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Proposal not active")); // 5. Fast-forward till after the voting phase. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); // 4. Vote in queued or later phase - e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(id, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); + e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(id, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Proposal not active")); } @@ -404,28 +402,25 @@ public void fail_voting_in_review_and_queued_phase() throws Throwable { public void fail_voting_multiple_times() throws Throwable { Hash256 creationTx = createSimpleProposal(gov, bob, "fail_voting_multiple_times"); Await.waitUntilTransactionIsExecuted(creationTx, neow3j); - int id = neow3j.getApplicationLog(creationTx).send() - .getApplicationLog().getExecutions().get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(creationTx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); // 2. Endorse - Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), - hash160(alice.getScriptHash())) - .signers(AccountSigner.calledByEntry(alice)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 endorseTx = gov.invokeFunction(ENDORSE, integer(id), hash160(alice.getScriptHash())).signers( + AccountSigner.calledByEntry(alice)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(endorseTx, neow3j); // 3. Fast-forward to the voting phase. ext.fastForwardOneBlock(PHASE_LENGTH); // 4. Vote the first time - Hash256 voteTx = gov.invokeFunction(VOTE, integer(id), integer(-1), - hash160(charlie.getScriptHash())) - .signers(AccountSigner.calledByEntry(charlie)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 voteTx = gov.invokeFunction(VOTE, integer(id), integer(-1), hash160(charlie.getScriptHash())).signers( + AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(voteTx, neow3j); // 5. Vote the second time - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(id, 1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(id, 1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Already voted on this proposal")); // 6. Check votes @@ -439,32 +434,39 @@ public void fail_voting_multiple_times() throws Throwable { @Test @Order(0) - public void fail_voting_with_non_member() throws Throwable { + public void fail_voting_with_non_member() { // Vote on the default proposal. Doesn't matter in what phase it is. - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(defaultProposalId, -1, bob.getScriptHash()).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(defaultProposalId, -1, bob.getScriptHash()).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @Test @Order(0) - public void fail_voting_on_non_existent_proposal() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(1000, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); + public void fail_voting_on_non_existent_proposal() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(1000, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Proposal doesn't exist")); } @Test @Order(0) - public void fail_voting_on_not_endorsed_proposal() throws Throwable { + public void fail_voting_on_not_endorsed_proposal() { // Vote on the default proposal. Doesn't matter in what phase it is. - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(defaultProposalId, -1, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(defaultProposalId, -1, charlie.getScriptHash()).signers( + AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Proposal not active")); } @Test @Order(0) - public void fail_voting_with_invalid_vote() throws Throwable { + public void fail_voting_with_invalid_vote() { // Vote on the default proposal. Doesn't matter in what phase it is. - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(defaultProposalId, 2, charlie.getScriptHash()).signers(AccountSigner.calledByEntry(charlie)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(defaultProposalId, 2, charlie.getScriptHash()).signers( + AccountSigner.calledByEntry(charlie)).sign()); assertTrue(e.getMessage().endsWith("Invalid vote")); } @@ -474,69 +476,58 @@ public void create_proposal_with_large_intents_and_offchainUri() throws Throwabl String offchainUri = "aabcababcababcababcabbcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcaabcabcabcabcabcabca"; Hash256 tx = gov.invokeFunction(CREATE, hash160(bob), - array( - array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "jjsldfjklkasjdfkljalkjasdf;lkjasddfd" + - "lfjkasdflkjasdfssldfjklkasjdfkljasasdfasfasdfasdf", - array( - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()) - ), CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "jjsldfjklkasjdfkljalkjasdf;lkjasddfd" + - "lfjkasdflkjasdfssldfjklkasjdfkljasasdfasfasdfasdf", - array( - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()) - ), CallFlags.ALL.getValue()), - array(NeoToken.SCRIPT_HASH, "jjsldfjklkasjdfkljalkjasdf;lkjasddfd" + - "lfjkasdflkjasdfssldfjklkasjdfkljasasdfasfasdfasdf", - array( - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - new Hash160(defaultAccountScriptHash()), - "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfiojpasodm" + - "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + - "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + - "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + - "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + - "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" - ), CallFlags.ALL.getValue()) - ), - string(offchainUri), - integer(-1)) - .signers(AccountSigner.calledByEntry(bob)) - .sign().send().getSendRawTransaction().getHash(); + array(array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue()), array(NeoToken.SCRIPT_HASH, + "jjsldfjklkasjdfkljalkjasdf;lkjasddfd" + + "lfjkasdflkjasdfssldfjklkasjdfkljasasdfasfasdfasdf", + array(new Hash160(defaultAccountScriptHash()), new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash())), CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, + "jjsldfjklkasjdfkljalkjasdf;lkjasddfd" + + "lfjkasdflkjasdfssldfjklkasjdfkljasasdfasfasdfasdf", + array(new Hash160(defaultAccountScriptHash()), new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash())), CallFlags.ALL.getValue()), + array(NeoToken.SCRIPT_HASH, + "jjsldfjklkasjdfkljalkjasdf;lkjasddfd" + + "lfjkasdflkjasdfssldfjklkasjdfkljasasdfasfasdfasdf", + array(new Hash160(defaultAccountScriptHash()), new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + new Hash160(defaultAccountScriptHash()), + "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfiojpasodm" + + "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + + "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + + "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + + "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi" + + "hlksajdfiojasdofjasodjflkjasdkfjlaijsdfi"), + CallFlags.ALL.getValue())), string(offchainUri), integer(-1)).signers( + AccountSigner.calledByEntry(bob)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); - int id = neow3j.getApplicationLog(tx).send().getApplicationLog().getExecutions().get(0) - .getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(tx).send().getApplicationLog().getExecutions().get(0).getStack().get( + 0).getInteger().intValue(); NeoInvokeFunction r = gov.callInvokeFunction(GET_PROPOSAL, Collections.singletonList(integer(id))); ProposalStruct p = new ProposalStruct(r.getInvocationResult().getStack().get(0).getList()); @@ -554,11 +545,9 @@ public void create_proposal_with_large_intents_and_offchainUri() throws Throwabl public void succeed_creating_exact_same_proposal_that_already_exists() throws IOException { // Recreate default proposal InvocationResult result = gov.invokeFunction(CREATE, hash160(alice.getScriptHash()), - array(array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue())), - string("default_proposal"), - integer(-1)).signers(AccountSigner.calledByEntry(alice)) - .callInvokeScript().getInvocationResult(); + array(array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue())), string("default_proposal"), integer(-1)).signers( + AccountSigner.calledByEntry(alice)).callInvokeScript().getInvocationResult(); assertThat(result.getStack().get(0).getInteger().intValue(), is(not(defaultProposalId))); assertThat(result.getStack().get(0).getInteger().intValue(), is(greaterThan(0))); } @@ -566,8 +555,9 @@ public void succeed_creating_exact_same_proposal_that_already_exists() throws IO @Test @Order(0) public void get_proposals() throws Throwable { - ContractParameter intents = array(array(NeoToken.SCRIPT_HASH, "balanceOf", - array(new Hash160(defaultAccountScriptHash())), CallFlags.ALL.getValue())); + ContractParameter intents = array( + array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue())); TestHelper.createAndEndorseProposal(gov, neow3j, bob, alice, intents, "some_proposal"); ProposalPaginatedStruct page = gov.getProposals(0, 1); @@ -580,35 +570,37 @@ public void get_proposals() throws Throwable { proposal = gov.getProposals(1, 1).items.get(0); assertThat(proposal.id, is(greaterThanOrEqualTo(1))); - String exception = gov.callInvokeFunction("getProposals", asList(integer(-1), integer(1))) - .getInvocationResult().getException(); + String exception = gov.callInvokeFunction("getProposals", + asList(integer(-1), integer(1))).getInvocationResult().getException(); assertThat(exception, containsString("Page number was negative")); - exception = gov.callInvokeFunction("getProposals", asList(integer(0), integer(0))) - .getInvocationResult().getException(); + exception = gov.callInvokeFunction("getProposals", + asList(integer(0), integer(0))).getInvocationResult().getException(); assertThat(exception, containsString("Page number was negative or zero")); } @Test @Order(0) public void get_number_of_proposals() throws IOException { - int result = gov.callInvokeFunction(GET_PROPOSAL_COUNT) - .getInvocationResult().getStack().get(0).getInteger().intValue(); + int result = gov.callInvokeFunction(GET_PROPOSAL_COUNT).getInvocationResult().getStack().get( + 0).getInteger().intValue(); // At least one because of the default proposal from the setup method. assertThat(result, is(greaterThanOrEqualTo(1))); } @Test @Order(0) - public void fail_pausing_contract_without_members_account() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(PAUSE).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_pausing_contract_without_members_account() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(PAUSE).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Not authorized")); } @Test @Order(0) - public void fail_unpausing_contract_without_members_account() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(UNPAUSE).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_unpausing_contract_without_members_account() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(UNPAUSE).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Not authorized")); } @@ -616,95 +608,107 @@ public void fail_unpausing_contract_without_members_account() throws Throwable { @Order(10) @Test public void succeed_pausing_contract() throws Throwable { - assertFalse(gov.callInvokeFunction(IS_PAUSED).getInvocationResult() - .getStack().get(0).getBoolean()); + assertFalse(gov.callInvokeFunction(IS_PAUSED).getInvocationResult().getStack().get(0).getBoolean()); Account membersAccount = createMultiSigAccount(1, alice, charlie); - Transaction tx = gov.invokeFunction(PAUSE) - .signers(AccountSigner.none(bob), AccountSigner.calledByEntry(membersAccount)) - .getUnsignedTransaction(); - Hash256 txHash = tx - .addWitness(Witness.create(tx.getHashData(), bob.getECKeyPair())) - .addMultiSigWitness(membersAccount.getVerificationScript(), alice) - .send().getSendRawTransaction().getHash(); + Transaction tx = gov.invokeFunction(PAUSE).signers(AccountSigner.none(bob), + AccountSigner.calledByEntry(membersAccount)).getUnsignedTransaction(); + Hash256 txHash = tx.addWitness(Witness.create(tx.getHashData(), bob.getECKeyPair())).addMultiSigWitness( + membersAccount.getVerificationScript(), alice).send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(txHash, neow3j); - assertTrue(gov.callInvokeFunction(IS_PAUSED).getInvocationResult() - .getStack().get(0).getBoolean()); + assertTrue(gov.callInvokeFunction(IS_PAUSED).getInvocationResult().getStack().get(0).getBoolean()); } @Test @Order(0) public void fail_execute_update_contract_directly() throws Throwable { - File nefFile = new File(this.getClass().getClassLoader() - .getResource(TESTCONTRACT_NEF_FILE.toString()).toURI()); + File nefFile = new File(this.getClass().getClassLoader().getResource(TESTCONTRACT_NEF_FILE.toString()).toURI()); NefFile nef = NefFile.readFromFile(nefFile); - File manifestFile = new File(this.getClass().getClassLoader() - .getResource(TESTCONTRACT_MANIFEST_FILE.toString()).toURI()); - ContractManifest manifest = getObjectMapper() - .readValue(manifestFile, ContractManifest.class); + File manifestFile = new File( + this.getClass().getClassLoader().getResource(TESTCONTRACT_MANIFEST_FILE.toString()).toURI()); + ContractManifest manifest = getObjectMapper().readValue(manifestFile, ContractManifest.class); String manifestString = getObjectMapper().writeValueAsString(manifest); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.updateContract(nef.toArray(), manifestString, null).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.updateContract(nef.toArray(), manifestString, null).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Method only callable by the contract itself")); } @Test @Order(0) - public void fail_create_proposal_calling_contract_management() throws Throwable { + public void fail_create_proposal_calling_contract_management() { IntentParam intent1 = IntentParam.addMemberProposal(gov.getScriptHash(), alice.getECKeyPair().getPublicKey()); IntentParam intent2 = new IntentParam(ContractManagement.SCRIPT_HASH, "destroy"); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.createProposal(alice.getScriptHash(), "fail_create_proposal_calling_contract_management", -1, intent1, intent2).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.createProposal(alice.getScriptHash(), "fail_create_proposal_calling_contract_management", -1, + intent1, intent2).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid intents")); } @Order(11) @Test - public void fail_change_param_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(CHANGE_PARAM, string(MIN_ACCEPTANCE_RATE_KEY), integer(50)).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_change_param_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(CHANGE_PARAM, string(MIN_ACCEPTANCE_RATE_KEY), integer(50)).signers( + AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(12) @Test - public void fail_add_member_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(ADD_MEMBER, publicKey(bob.getECKeyPair().getPublicKey().getEncoded(true))).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_add_member_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(ADD_MEMBER, + publicKey(bob.getECKeyPair().getPublicKey().getEncoded(true))).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(13) @Test - public void fail_remove_member_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.invokeFunction(REMOVE_MEMBER, publicKey(bob.getECKeyPair().getPublicKey().getEncoded(true))).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_remove_member_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.invokeFunction(REMOVE_MEMBER, + publicKey(bob.getECKeyPair().getPublicKey().getEncoded(true))).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(14) @Test - public void fail_execute_proposal_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(defaultProposalId).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_execute_proposal_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(defaultProposalId).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(15) @Test - public void fail_vote_on_proposal_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.vote(defaultProposalId, 1, alice.getScriptHash()).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_vote_on_proposal_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.vote(defaultProposalId, 1, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(16) @Test - public void fail_endorse_proposal_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.endorseProposal(defaultProposalId, alice.getScriptHash()).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_endorse_proposal_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.endorseProposal(defaultProposalId, alice.getScriptHash()).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(17) @Test - public void fail_update_contract_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.updateContract(new byte[]{0x01, 0x02, 0x03}, "the manifest", null).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_update_contract_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.updateContract(new byte[]{0x01, 0x02, 0x03}, "the manifest", null).signers( + AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @@ -712,45 +716,34 @@ public void fail_update_contract_on_paused_contract() throws Throwable { @Order(19) @Test public void succeed_unpausing_contract() throws Throwable { - assertTrue(gov.callInvokeFunction(IS_PAUSED).getInvocationResult() - .getStack().get(0).getBoolean()); + assertTrue(gov.callInvokeFunction(IS_PAUSED).getInvocationResult().getStack().get(0).getBoolean()); Account membersAccount = createMultiSigAccount(1, alice, charlie); - Transaction tx = gov.invokeFunction(UNPAUSE) - .signers(AccountSigner.none(bob), AccountSigner.calledByEntry(membersAccount)) - .getUnsignedTransaction(); - Hash256 txHash = tx - .addWitness(Witness.create(tx.getHashData(), bob.getECKeyPair())) - .addMultiSigWitness(membersAccount.getVerificationScript(), alice) - .send().getSendRawTransaction().getHash(); + Transaction tx = gov.invokeFunction(UNPAUSE).signers(AccountSigner.none(bob), + AccountSigner.calledByEntry(membersAccount)).getUnsignedTransaction(); + Hash256 txHash = tx.addWitness(Witness.create(tx.getHashData(), bob.getECKeyPair())).addMultiSigWitness( + membersAccount.getVerificationScript(), alice).send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(txHash, neow3j); - assertFalse(gov.callInvokeFunction(IS_PAUSED).getInvocationResult() - .getStack().get(0).getBoolean()); + assertFalse(gov.callInvokeFunction(IS_PAUSED).getInvocationResult().getStack().get(0).getBoolean()); } @Test @Order(20) public void execute_proposal_with_update_contract() throws Throwable { - File nefFile = new File(this.getClass().getClassLoader() - .getResource(TESTCONTRACT_NEF_FILE.toString()).toURI()); + File nefFile = new File(this.getClass().getClassLoader().getResource(TESTCONTRACT_NEF_FILE.toString()).toURI()); NefFile nef = NefFile.readFromFile(nefFile); - File manifestFile = new File(this.getClass().getClassLoader() - .getResource(TESTCONTRACT_MANIFEST_FILE.toString()).toURI()); - ContractManifest manifest = getObjectMapper() - .readValue(manifestFile, ContractManifest.class); + File manifestFile = new File( + this.getClass().getClassLoader().getResource(TESTCONTRACT_MANIFEST_FILE.toString()).toURI()); + ContractManifest manifest = getObjectMapper().readValue(manifestFile, ContractManifest.class); byte[] manifestBytes = getObjectMapper().writeValueAsBytes(manifest); ContractParameter data = string("some data"); ContractParameter intents = array( - array( - gov.getScriptHash(), - UPDATE_CONTRACT, - array(nef.toArray(), manifestBytes, data), - CallFlags.ALL.getValue() - )); + array(gov.getScriptHash(), UPDATE_CONTRACT, array(nef.toArray(), manifestBytes, data), + CallFlags.ALL.getValue())); String offchainUri = "execute_proposal_with_update_contract"; // 1. Create and endorse proposal @@ -763,13 +756,12 @@ public void execute_proposal_with_update_contract() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Hash256 tx = gov.invokeFunction(EXECUTE, integer(id)) - .signers(AccountSigner.calledByEntry(charlie)) - .sign().send().getSendRawTransaction().getHash(); + Hash256 tx = gov.invokeFunction(EXECUTE, integer(id)).signers( + AccountSigner.calledByEntry(charlie)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); - NeoApplicationLog.Execution execution = neow3j.getApplicationLog(tx).send() - .getApplicationLog().getExecutions().get(0); + NeoApplicationLog.Execution execution = neow3j.getApplicationLog( + tx).send().getApplicationLog().getExecutions().get(0); Notification n = execution.getNotifications().get(0); assertThat(n.getEventName(), is("UpdatingContract")); assertThat(n.getContract(), is(gov.getScriptHash())); diff --git a/src/test/java/com/axlabs/neo/grantshares/GrantSharesTreasuryTest.java b/src/test/java/com/axlabs/neo/grantshares/GrantSharesTreasuryTest.java index ebdbda8..2b2ed1f 100644 --- a/src/test/java/com/axlabs/neo/grantshares/GrantSharesTreasuryTest.java +++ b/src/test/java/com/axlabs/neo/grantshares/GrantSharesTreasuryTest.java @@ -46,17 +46,17 @@ import java.util.List; import java.util.Map; -import static com.axlabs.neo.grantshares.util.TestHelper.ALICE; -import static com.axlabs.neo.grantshares.util.TestHelper.BOB; -import static com.axlabs.neo.grantshares.util.TestHelper.CHARLIE; -import static com.axlabs.neo.grantshares.util.TestHelper.DENISE; -import static com.axlabs.neo.grantshares.util.TestHelper.EVE; -import static com.axlabs.neo.grantshares.util.TestHelper.EXECUTE; -import static com.axlabs.neo.grantshares.util.TestHelper.IS_PAUSED; -import static com.axlabs.neo.grantshares.util.TestHelper.PAUSE; -import static com.axlabs.neo.grantshares.util.TestHelper.PHASE_LENGTH; -import static com.axlabs.neo.grantshares.util.TestHelper.UNPAUSE; -import static com.axlabs.neo.grantshares.util.TestHelper.UPDATE_CONTRACT; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.EXECUTE; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.IS_PAUSED; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.PAUSE; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.UNPAUSE; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.UPDATE_CONTRACT; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.ALICE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.BOB; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.CHARLIE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.DENISE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.EVE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.PHASE_LENGTH; import static com.axlabs.neo.grantshares.util.TestHelper.createAndEndorseProposal; import static com.axlabs.neo.grantshares.util.TestHelper.createMultiSigAccount; import static com.axlabs.neo.grantshares.util.TestHelper.prepareDeployParameter; @@ -74,10 +74,12 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.Is.is; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; @ContractTest(contracts = {GrantSharesGov.class, GrantSharesTreasury.class}, - blockTime = 1, configFile = "default.neo-express", batchFile = "setup.batch") + blockTime = 1, configFile = "default.neo-express", batchFile = "setup.batch") @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class GrantSharesTreasuryTest { @@ -204,29 +206,37 @@ public void succeed_voting_on_committee_member() throws Throwable { @Test @Order(0) - public void fail_calling_add_whitelisted_token_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.addWhitelistedToken(GasToken.SCRIPT_HASH, 1).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_add_whitelisted_token_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.addWhitelistedToken(GasToken.SCRIPT_HASH, 1).signers(AccountSigner.calledByEntry(alice)) + .sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @Test @Order(0) - public void fail_calling_remove_whitelisted_token_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.removeWhitelistedToken(GasToken.SCRIPT_HASH).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_remove_whitelisted_token_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.removeWhitelistedToken(GasToken.SCRIPT_HASH).signers(AccountSigner.calledByEntry(alice)) + .sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @Test @Order(0) - public void fail_calling_add_funder_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.addFunder(alice.getScriptHash(), alice.getECKeyPair().getPublicKey()).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_add_funder_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.addFunder(alice.getScriptHash(), alice.getECKeyPair().getPublicKey()) + .signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @Test @Order(0) - public void fail_calling_remove_funder_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.removeFunder(charlie.getScriptHash()).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_calling_remove_funder_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.removeFunder(charlie.getScriptHash()).signers(AccountSigner.calledByEntry(alice)) + .sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @@ -254,7 +264,9 @@ public void fail_execute_update_contract_directly() throws Throwable { ContractParameter data = string("update contract"); - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.invokeFunction(UPDATE_CONTRACT, byteArray(nef.toArray()), byteArray(manifestBytes), data).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.invokeFunction(UPDATE_CONTRACT, byteArray(nef.toArray()), byteArray(manifestBytes), data) + .signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @@ -275,7 +287,8 @@ public void fail_release_tokens_with_non_whitelisted_token() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Token not whitelisted")); } @@ -296,14 +309,17 @@ public void fail_release_tokens_with_to_high_amount() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Above token's max funding amount")); } @Test @Order(0) - public void fail_calling_release_tokens_directly() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.releaseTokens(GasToken.SCRIPT_HASH, alice.getScriptHash(), BigInteger.ONE).signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_calling_release_tokens_directly() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.releaseTokens(GasToken.SCRIPT_HASH, alice.getScriptHash(), BigInteger.ONE) + .signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Not authorised")); } @@ -311,7 +327,8 @@ public void fail_calling_release_tokens_directly() throws Throwable { @Order(0) public void fail_adding_invalid_funder() throws Throwable { ContractParameter intent = new IntentParam(treasury.getScriptHash(), "addFunder", - byteArray("3ff68d232a60f23a5805b8c40f7e61747f"), array(Collections.singletonList(alice.getECKeyPair().getPublicKey()))); + byteArray("3ff68d232a60f23a5805b8c40f7e61747f"), + array(Collections.singletonList(alice.getECKeyPair().getPublicKey()))); String offchainUri = "fail_adding_invalid_funder"; // 1. Create and endorse proposal @@ -323,7 +340,8 @@ public void fail_adding_invalid_funder() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid funder hash")); } @@ -342,7 +360,8 @@ public void fail_adding_funder_with_no_public_keys() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("List of public keys is empty")); } @@ -363,7 +382,8 @@ public void fail_adding_funder_with_invalid_public_key() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid public key")); } @@ -386,9 +406,11 @@ public void fail_setting_funders_multisig_threshold_ratio_with_invalid_value() t // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id1).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id1).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid threshold ratio")); - e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id2).signers(AccountSigner.calledByEntry(alice)).sign()); + e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id2).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid threshold ratio")); } @@ -408,7 +430,8 @@ public void fail_adding_whitelisted_token_with_invalid_token() throws Throwable // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid token hash")); } @@ -428,7 +451,8 @@ public void fail_adding_whitelisted_token_with_invalid_max_funding_amount() thro // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Invalid max funding amount")); } @@ -514,7 +538,8 @@ public void fail_adding_already_added_funder() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Already a funder")); } @@ -562,7 +587,8 @@ public void fail_removing_nonexistant_funder() throws Throwable { // 3. Skip till after vote and queued phase, then execute. ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Not a funder")); } @@ -746,50 +772,62 @@ public void succeed_pausing_contract() throws Throwable { @Order(21) @Test - public void fail_add_funder_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.addFunder(alice.getScriptHash(), alice.getECKeyPair().getPublicKey()).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_add_funder_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.addFunder(alice.getScriptHash(), alice.getECKeyPair().getPublicKey()) + .signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(22) @Test - public void fail_remove_funder_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.removeFunder(alice.getScriptHash()).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_remove_funder_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.removeFunder(alice.getScriptHash()).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(23) @Test - public void fail_add_whitelisted_token_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.addWhitelistedToken(GasToken.SCRIPT_HASH, 1).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_add_whitelisted_token_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.addWhitelistedToken(GasToken.SCRIPT_HASH, 1).signers(AccountSigner.calledByEntry(alice)) + .sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(24) @Test - public void fail_remove_whitelisted_token_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.removeWhitelistedToken(GasToken.SCRIPT_HASH).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_remove_whitelisted_token_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.removeWhitelistedToken(GasToken.SCRIPT_HASH).signers(AccountSigner.calledByEntry(alice)) + .sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(25) @Test - public void fail_release_tokens_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.releaseTokens(GasToken.SCRIPT_HASH, alice.getScriptHash(), BigInteger.ONE).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_release_tokens_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.releaseTokens(GasToken.SCRIPT_HASH, alice.getScriptHash(), BigInteger.ONE) + .signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(26) @Test - public void fail_vote_on_committee_member_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.voteCommitteeMemberWithLeastVotes().signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_vote_on_committee_member_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.voteCommitteeMemberWithLeastVotes().signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } @Order(27) @Test - public void fail_update_contract_on_paused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.updateContract(new byte[]{0x01, 0x02, 0x03}, "the manifest", null).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_update_contract_on_paused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.updateContract(new byte[]{0x01, 0x02, 0x03}, "the manifest", null) + .signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is paused")); } diff --git a/src/test/java/com/axlabs/neo/grantshares/ProposalExecutionsTest.java b/src/test/java/com/axlabs/neo/grantshares/ProposalExecutionsTest.java index 5e10a25..e157711 100644 --- a/src/test/java/com/axlabs/neo/grantshares/ProposalExecutionsTest.java +++ b/src/test/java/com/axlabs/neo/grantshares/ProposalExecutionsTest.java @@ -23,19 +23,19 @@ import java.math.BigInteger; -import static com.axlabs.neo.grantshares.util.TestHelper.ALICE; -import static com.axlabs.neo.grantshares.util.TestHelper.BOB; -import static com.axlabs.neo.grantshares.util.TestHelper.CHANGE_PARAM; -import static com.axlabs.neo.grantshares.util.TestHelper.CHARLIE; -import static com.axlabs.neo.grantshares.util.TestHelper.CREATE; -import static com.axlabs.neo.grantshares.util.TestHelper.DENISE; -import static com.axlabs.neo.grantshares.util.TestHelper.EVE; -import static com.axlabs.neo.grantshares.util.TestHelper.EXECUTE; -import static com.axlabs.neo.grantshares.util.TestHelper.FLORIAN; -import static com.axlabs.neo.grantshares.util.TestHelper.MIN_ACCEPTANCE_RATE_KEY; -import static com.axlabs.neo.grantshares.util.TestHelper.PHASE_LENGTH; -import static com.axlabs.neo.grantshares.util.TestHelper.PROPOSAL_EXECUTED; -import static com.axlabs.neo.grantshares.util.TestHelper.REVIEW_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.Events.PROPOSAL_EXECUTED; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.CHANGE_PARAM; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.CREATE; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.EXECUTE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.ALICE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.BOB; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.CHARLIE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.DENISE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.EVE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.FLORIAN; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.MIN_ACCEPTANCE_RATE_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterNames.REVIEW_LENGTH_KEY; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.PHASE_LENGTH; import static com.axlabs.neo.grantshares.util.TestHelper.createAndEndorseProposal; import static com.axlabs.neo.grantshares.util.TestHelper.prepareDeployParameter; import static com.axlabs.neo.grantshares.util.TestHelper.voteForProposal; @@ -50,7 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @ContractTest(contracts = GrantSharesGov.class, blockTime = 1, configFile = "default.neo-express", - batchFile = "setup.batch") + batchFile = "setup.batch") public class ProposalExecutionsTest { @RegisterExtension @@ -87,8 +87,9 @@ public static void setUp() throws Throwable { } @Test - public void fail_executing_non_existent_proposal() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(1000).signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_executing_non_existent_proposal() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(1000).signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Proposal doesn't exist")); } @@ -109,7 +110,8 @@ public void fail_executing_proposal_that_wasnt_endorsed() throws Throwable { .getStack().get(0).getInteger().intValue(); // 2. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Proposal not in execution phase")); } @@ -125,7 +127,8 @@ public void fail_executing_proposal_without_votes() throws Throwable { ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH + PHASE_LENGTH); // 2. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Quorum not reached")); } @@ -154,7 +157,8 @@ public void fail_executing_accepted_proposal_multiple_times() throws Throwable { .getNotifications().get(1).getEventName(), is(PROPOSAL_EXECUTED)); // 4. Call execute the second time and fail. - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Proposal already executed")); } @@ -225,7 +229,8 @@ public void fail_executing_proposal_quorum_reached_but_rejected() throws Throwab ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); // 3. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Proposal rejected")); } @@ -248,7 +253,8 @@ public void fail_executing_proposal_quorum_reached_but_all_abstained() throws Th ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); // 3. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Proposal rejected")); } @@ -268,7 +274,8 @@ public void fail_executing_proposal_quorum_not_reached() throws Throwable { ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); // 3. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Quorum not reached")); } @@ -289,7 +296,8 @@ public void fail_executing_proposal_with_different_quorum_not_reached() throws T ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); // 3. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Quorum not reached")); } @@ -312,7 +320,8 @@ public void fail_executing_proposal_with_different_quorum_reached_different_rate ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH); // 3. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Proposal rejected")); } @@ -356,7 +365,8 @@ public void fail_executing_expired_proposal() throws Throwable { ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH + PHASE_LENGTH); // skip voting, time lock, expiration phase // 2. Call execute - Exception e = assertThrows(TransactionConfigurationException.class, () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> gov.execute(id).signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Proposal expired")); } } diff --git a/src/test/java/com/axlabs/neo/grantshares/TreasuryMultiSigTest.java b/src/test/java/com/axlabs/neo/grantshares/TreasuryMultiSigTest.java index 34d79f6..78b7034 100644 --- a/src/test/java/com/axlabs/neo/grantshares/TreasuryMultiSigTest.java +++ b/src/test/java/com/axlabs/neo/grantshares/TreasuryMultiSigTest.java @@ -36,14 +36,14 @@ import java.util.List; import java.util.Map; -import static com.axlabs.neo.grantshares.util.TestHelper.ALICE; -import static com.axlabs.neo.grantshares.util.TestHelper.BOB; -import static com.axlabs.neo.grantshares.util.TestHelper.CHARLIE; -import static com.axlabs.neo.grantshares.util.TestHelper.DENISE; -import static com.axlabs.neo.grantshares.util.TestHelper.EVE; -import static com.axlabs.neo.grantshares.util.TestHelper.IS_PAUSED; -import static com.axlabs.neo.grantshares.util.TestHelper.PAUSE; -import static com.axlabs.neo.grantshares.util.TestHelper.PHASE_LENGTH; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.IS_PAUSED; +import static com.axlabs.neo.grantshares.util.TestHelper.GovernanceMethods.PAUSE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.ALICE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.BOB; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.CHARLIE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.DENISE; +import static com.axlabs.neo.grantshares.util.TestHelper.Members.EVE; +import static com.axlabs.neo.grantshares.util.TestHelper.ParameterValues.PHASE_LENGTH; import static com.axlabs.neo.grantshares.util.TestHelper.createAndEndorseProposal; import static com.axlabs.neo.grantshares.util.TestHelper.createMultiSigAccount; import static com.axlabs.neo.grantshares.util.TestHelper.prepareDeployParameter; @@ -53,10 +53,12 @@ import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; @ContractTest(contracts = {GrantSharesGov.class, GrantSharesTreasury.class}, - blockTime = 1, configFile = "default.neo-express", batchFile = "setup.batch") + blockTime = 1, configFile = "default.neo-express", batchFile = "setup.batch") @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class TreasuryMultiSigTest { private static final int NEO_MAX_AMOUNT = 100; @@ -180,8 +182,9 @@ public void calc_funders_multisig_address() throws Throwable { @Test @Order(0) - public void fail_execute_drain_on_unpaused_contract() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.drain().signers(AccountSigner.calledByEntry(alice)).sign()); + public void fail_execute_drain_on_unpaused_contract() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.drain().signers(AccountSigner.calledByEntry(alice)).sign()); assertTrue(e.getMessage().endsWith("Contract is not paused")); } @@ -207,8 +210,9 @@ public void succeed_pausing_contract() throws Throwable { @Order(11) @Test - public void fail_execute_drain_with_non_funder() throws Throwable { - Exception e = assertThrows(TransactionConfigurationException.class, () -> treasury.drain().signers(AccountSigner.calledByEntry(bob)).sign()); + public void fail_execute_drain_with_non_funder() { + TransactionConfigurationException e = assertThrows(TransactionConfigurationException.class, + () -> treasury.drain().signers(AccountSigner.calledByEntry(bob)).sign()); assertTrue(e.getMessage().endsWith("Not authorized")); } diff --git a/src/test/java/com/axlabs/neo/grantshares/util/TestHelper.java b/src/test/java/com/axlabs/neo/grantshares/util/TestHelper.java index d59c07d..d420e0d 100644 --- a/src/test/java/com/axlabs/neo/grantshares/util/TestHelper.java +++ b/src/test/java/com/axlabs/neo/grantshares/util/TestHelper.java @@ -4,18 +4,15 @@ import io.neow3j.contract.SmartContract; import io.neow3j.crypto.ECKeyPair; import io.neow3j.protocol.Neow3j; -import io.neow3j.protocol.core.response.NeoApplicationLog; import io.neow3j.transaction.AccountSigner; import io.neow3j.transaction.TransactionBuilder; import io.neow3j.types.CallFlags; import io.neow3j.types.ContractParameter; import io.neow3j.types.Hash160; import io.neow3j.types.Hash256; -import io.neow3j.types.NeoVMStateType; import io.neow3j.utils.Await; import io.neow3j.wallet.Account; -import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; @@ -28,64 +25,9 @@ import static io.neow3j.types.ContractParameter.integer; import static io.neow3j.types.ContractParameter.publicKey; import static io.neow3j.types.ContractParameter.string; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; public class TestHelper { - // Account names available in the neo-express config file. - public static final String ALICE = "NM7Aky765FG8NhhwtxjXRx7jEL1cnw7PBP"; - public static final String BOB = "NZpsgXn9VQQoLexpuXJsrX8BsoyAhKUyiX"; - public static final String CHARLIE = "NdbtgSku2qLuwsBBzLx3FLtmmMdm32Ktor"; - public static final String DENISE = "NerDv9t8exrQRrP11jjvZKXzSXvTnmfDTo"; - public static final String EVE = "NZ539Rd57v5NEtAdkHyFGaWj1uGt2DecUL"; - public static final String FLORIAN = "NRy5bp81kScYFZHLfMBXuubFfRyboVyu7G"; - - // GrantSharesGov contract methods - public static final String CREATE = "createProposal"; - public static final String GET_PROPOSAL = "getProposal"; - public static final String GET_PROPOSALS = "getProposals"; - public static final String GET_PARAMETER = "getParameter"; - public static final String GET_MEMBERS = "getMembers"; - public static final String GET_MEMBERS_COUNT = "getMembersCount"; - public static final String GET_PROPOSAL_COUNT = "getProposalCount"; - public static final String PAUSE = "pause"; - public static final String UNPAUSE = "unpause"; - public static final String IS_PAUSED = "isPaused"; - public static final String CALC_MEMBER_MULTI_SIG_ACC = "calcMembersMultiSigAccount"; - public static final String ENDORSE = "endorseProposal"; - public static final String VOTE = "vote"; - public static final String EXECUTE = "execute"; - public static final String CHANGE_PARAM = "changeParam"; - public static final String ADD_MEMBER = "addMember"; - public static final String REMOVE_MEMBER = "removeMember"; - public static final String UPDATE_CONTRACT = "updateContract"; - - // events - public static final String PROPOSAL_CREATED = "ProposalCreated"; - public static final String PROPOSAL_ENDORSED = "ProposalEndorsed"; - public static final String PROPOSAL_EXECUTED = "ProposalExecuted"; - public static final String VOTED = "Voted"; - public static final String MEMBER_ADDED = "MemberAdded"; - public static final String MEMBER_REMOVED = "MemberRemoved"; - public static final String PARAMETER_CHANGED = "ParameterChanged"; - - // governance parameters values - public static final int PHASE_LENGTH = 60; // seconds - public static final int MIN_ACCEPTANCE_RATE = 50; - public static final int MIN_QUORUM = 50; - public static final int MULTI_SIG_THRESHOLD_RATIO = 50; - - // parameter names - public static final String REVIEW_LENGTH_KEY = "review_len"; - public static final String VOTING_LENGTH_KEY = "voting_len"; - public static final String TIMELOCK_LENGTH_KEY = "timelock_len"; - public static final String EXPIRATION_LENGTH_KEY = "expiration_len"; - public static final String MIN_ACCEPTANCE_RATE_KEY = "min_accept_rate"; - public static final String MIN_QUORUM_KEY = "min_quorum"; - public static final String MULTI_SIG_THRESHOLD_KEY = "threshold"; - static MessageDigest hasher; static { @@ -97,95 +39,136 @@ public class TestHelper { } public static ContractParameter prepareDeployParameter(Account... members) { - return array( - array(Arrays.stream(members) - .map(m -> publicKey(m.getECKeyPair().getPublicKey().getEncoded(true))) + return array(array(Arrays.stream(members).map(m -> publicKey(m.getECKeyPair().getPublicKey().getEncoded(true))) .collect(Collectors.toList())), - array( - REVIEW_LENGTH_KEY, PHASE_LENGTH * 1000, - VOTING_LENGTH_KEY, PHASE_LENGTH * 1000, - TIMELOCK_LENGTH_KEY, PHASE_LENGTH * 1000, - EXPIRATION_LENGTH_KEY, PHASE_LENGTH * 1000, - MIN_ACCEPTANCE_RATE_KEY, MIN_ACCEPTANCE_RATE, - MIN_QUORUM_KEY, MIN_QUORUM, - MULTI_SIG_THRESHOLD_KEY, MULTI_SIG_THRESHOLD_RATIO - ) - ); + array(ParameterNames.REVIEW_LENGTH_KEY, ParameterValues.PHASE_LENGTH * 1000, + ParameterNames.VOTING_LENGTH_KEY, ParameterValues.PHASE_LENGTH * 1000, + ParameterNames.TIMELOCK_LENGTH_KEY, ParameterValues.PHASE_LENGTH * 1000, + ParameterNames.EXPIRATION_LENGTH_KEY, ParameterValues.PHASE_LENGTH * 1000, + ParameterNames.MIN_ACCEPTANCE_RATE_KEY, ParameterValues.MIN_ACCEPTANCE_RATE, + ParameterNames.MIN_QUORUM_KEY, ParameterValues.MIN_QUORUM, + ParameterNames.MULTI_SIG_THRESHOLD_KEY, ParameterValues.MULTI_SIG_THRESHOLD_RATIO)); } - public static Hash256 createSimpleProposal(SmartContract contract, Account proposer, - String offchainUri) throws Throwable { - - return contract.invokeFunction(CREATE, hash160(proposer), - array( - array( - NeoToken.SCRIPT_HASH, - "balanceOf", - array(new Hash160(defaultAccountScriptHash())), - CallFlags.ALL.getValue() - ) - ), - string(offchainUri), - integer(-1)) - .signers(AccountSigner.calledByEntry(proposer)) - .sign().send().getSendRawTransaction().getHash(); - } + public static Hash256 createSimpleProposal(SmartContract contract, Account proposer, String offchainUri) + throws Throwable { + return contract.invokeFunction(GovernanceMethods.CREATE, hash160(proposer), + array(array(NeoToken.SCRIPT_HASH, "balanceOf", array(new Hash160(defaultAccountScriptHash())), + CallFlags.ALL.getValue())), string(offchainUri), integer(-1)) + .signers(AccountSigner.calledByEntry(proposer)).sign().send().getSendRawTransaction().getHash(); + } public static int createAndEndorseProposal(GrantSharesGovContract gov, Neow3j neow3j, Account proposer, - Account endorser, ContractParameter intents, String offchainUri) throws Throwable { - TransactionBuilder b = gov.invokeFunction(CREATE, hash160(proposer), intents, string(offchainUri), - integer(-1)); + Account endorser, ContractParameter intents, String offchainUri) + throws Throwable { + TransactionBuilder b = gov.invokeFunction(GovernanceMethods.CREATE, hash160(proposer), intents, + string(offchainUri), integer(-1)); return sendAndEndorseProposal(gov, neow3j, proposer, endorser, b); } public static int createAndEndorseProposal(GrantSharesGovContract gov, Neow3j neow3j, Account proposer, Account endorser, ContractParameter intents, String offchainUri, int acceptanceRate, int quorum) throws Throwable { - TransactionBuilder b = gov.invokeFunction(CREATE, hash160(proposer), intents, string(offchainUri), - integer(-1), integer(acceptanceRate), integer(quorum)); + TransactionBuilder b = gov.invokeFunction(GovernanceMethods.CREATE, hash160(proposer), intents, + string(offchainUri), integer(-1), integer(acceptanceRate), integer(quorum)); return sendAndEndorseProposal(gov, neow3j, proposer, endorser, b); } private static int sendAndEndorseProposal(GrantSharesGovContract gov, Neow3j neow3j, Account proposer, - Account endorser, TransactionBuilder b) throws Throwable { - Hash256 tx = b.signers(AccountSigner.calledByEntry(proposer)) - .sign().send().getSendRawTransaction().getHash(); + Account endorser, TransactionBuilder b) + throws Throwable { + Hash256 tx = b.signers(AccountSigner.calledByEntry(proposer)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); - int id = neow3j.getApplicationLog(tx).send().getApplicationLog() - .getExecutions().get(0).getStack().get(0).getInteger().intValue(); + int id = neow3j.getApplicationLog(tx).send().getApplicationLog().getExecutions().get(0).getStack().get(0) + .getInteger().intValue(); // 2. endorse proposal - tx = gov.invokeFunction(ENDORSE, integer(id), hash160(endorser)) - .signers(AccountSigner.calledByEntry(endorser)) - .sign().send().getSendRawTransaction().getHash(); + tx = gov.invokeFunction(GovernanceMethods.ENDORSE, integer(id), hash160(endorser)) + .signers(AccountSigner.calledByEntry(endorser)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); return id; } - public static void voteForProposal(GrantSharesGovContract gov, Neow3j neow3j, int id, - Account endorserAndVoter) throws Throwable { - Hash256 tx = gov.invokeFunction(VOTE, integer(id), integer(1), hash160(endorserAndVoter)) - .signers(AccountSigner.calledByEntry(endorserAndVoter)) - .sign().send().getSendRawTransaction().getHash(); + public static void voteForProposal(GrantSharesGovContract gov, Neow3j neow3j, int id, Account endorserAndVoter) + throws Throwable { + Hash256 tx = gov.invokeFunction(GovernanceMethods.VOTE, integer(id), integer(1), hash160(endorserAndVoter)) + .signers(AccountSigner.calledByEntry(endorserAndVoter)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); } public static void voteForProposal(GrantSharesGovContract gov, Neow3j neow3j, int id, int vote, - Account endorserAndVoter) throws Throwable { - Hash256 tx = gov.invokeFunction(VOTE, integer(id), integer(vote), - hash160(endorserAndVoter)) - .signers(AccountSigner.calledByEntry(endorserAndVoter)) - .sign().send().getSendRawTransaction().getHash(); + Account endorserAndVoter) + throws Throwable { + Hash256 tx = gov.invokeFunction(GovernanceMethods.VOTE, integer(id), integer(vote), hash160(endorserAndVoter)) + .signers(AccountSigner.calledByEntry(endorserAndVoter)).sign().send().getSendRawTransaction().getHash(); Await.waitUntilTransactionIsExecuted(tx, neow3j); } public static Account createMultiSigAccount(int threshold, Account... accounts) { - List pubKeys = Arrays.stream(accounts) - .map(a -> a.getECKeyPair().getPublicKey()) + List pubKeys = Arrays.stream(accounts).map(a -> a.getECKeyPair().getPublicKey()) .collect(Collectors.toList()); return Account.createMultiSigAccount(pubKeys, threshold); } + + public static class Members { + // Account names available in the neo-express config file. + public static final String ALICE = "NM7Aky765FG8NhhwtxjXRx7jEL1cnw7PBP"; + public static final String BOB = "NZpsgXn9VQQoLexpuXJsrX8BsoyAhKUyiX"; + public static final String CHARLIE = "NdbtgSku2qLuwsBBzLx3FLtmmMdm32Ktor"; + public static final String DENISE = "NerDv9t8exrQRrP11jjvZKXzSXvTnmfDTo"; + public static final String EVE = "NZ539Rd57v5NEtAdkHyFGaWj1uGt2DecUL"; + public static final String FLORIAN = "NRy5bp81kScYFZHLfMBXuubFfRyboVyu7G"; + } + + public static class GovernanceMethods { + public static final String ADD_MEMBER = "addMember"; + public static final String CALC_MEMBER_MULTI_SIG_ACC = "calcMembersMultiSigAccount"; + public static final String CHANGE_PARAM = "changeParam"; + public static final String CREATE = "createProposal"; + public static final String ENDORSE = "endorseProposal"; + public static final String EXECUTE = "execute"; + public static final String GET_MEMBERS = "getMembers"; + public static final String GET_MEMBERS_COUNT = "getMembersCount"; + public static final String GET_PARAMETER = "getParameter"; + public static final String GET_PROPOSAL = "getProposal"; + public static final String GET_PROPOSALS = "getProposals"; + public static final String GET_PROPOSAL_COUNT = "getProposalCount"; + public static final String IS_PAUSED = "isPaused"; + public static final String PAUSE = "pause"; + public static final String REMOVE_MEMBER = "removeMember"; + public static final String UNPAUSE = "unpause"; + public static final String UPDATE_CONTRACT = "updateContract"; + public static final String VOTE = "vote"; + } + + public static class Events { + public static final String MEMBER_ADDED = "MemberAdded"; + public static final String MEMBER_REMOVED = "MemberRemoved"; + public static final String PARAMETER_CHANGED = "ParameterChanged"; + public static final String PROPOSAL_CREATED = "ProposalCreated"; + public static final String PROPOSAL_ENDORSED = "ProposalEndorsed"; + public static final String PROPOSAL_EXECUTED = "ProposalExecuted"; + public static final String VOTED = "Voted"; + } + + public static class ParameterNames { + public static final String EXPIRATION_LENGTH_KEY = "expiration_len"; + public static final String MIN_ACCEPTANCE_RATE_KEY = "min_accept_rate"; + public static final String MIN_QUORUM_KEY = "min_quorum"; + public static final String MULTI_SIG_THRESHOLD_KEY = "threshold"; + public static final String REVIEW_LENGTH_KEY = "review_len"; + public static final String TIMELOCK_LENGTH_KEY = "timelock_len"; + public static final String VOTING_LENGTH_KEY = "voting_len"; + } + + public static class ParameterValues { + public static final int MIN_ACCEPTANCE_RATE = 50; + public static final int MIN_QUORUM = 50; + public static final int MULTI_SIG_THRESHOLD_RATIO = 50; + public static final int PHASE_LENGTH = 60; // seconds + } + }