Skip to content

Commit

Permalink
Apply changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
OT-kraftchain committed Dec 12, 2024
1 parent 6c8972b commit 820269f
Show file tree
Hide file tree
Showing 11 changed files with 609 additions and 510 deletions.
41 changes: 41 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/main/java/com/axlabs/neo/grantshares/GrantSharesGov.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
50 changes: 38 additions & 12 deletions src/test/java/com/axlabs/neo/grantshares/GovernanceMembersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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"));
}

Expand All @@ -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()
Expand Down Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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"));
}

Expand All @@ -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()
Expand Down Expand Up @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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"));
}

Expand All @@ -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"));
}

Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
Loading

0 comments on commit 820269f

Please sign in to comment.