Skip to content

Commit

Permalink
Merge pull request #52 from Alien-Worlds/DEMZNE-1021_eosdac-Disable-c…
Browse files Browse the repository at this point in the history
…andidate-feature

disable candidate feature WIP
  • Loading branch information
angelol authored Oct 4, 2022
2 parents 6de3e16 + ff5f9d0 commit 3c36a11
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 46 deletions.
4 changes: 3 additions & 1 deletion contract-shared-headers/daccustodian_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ namespace eosdac {

ACTION nominatecane(const name &cand, const eosio::asset &requestedpay, const name &dac_id);
ACTION withdrawcane(const name &cand, const name &dac_id);
ACTION removecand(const name &cand, const name &dac_id);
ACTION firecand(const name &cand, const bool lockupStake, const name &dac_id);
ACTION resigncust(const name &cust, const name &dac_id);
ACTION firecust(const name &cust, const name &dac_id);
Expand Down Expand Up @@ -531,7 +532,8 @@ namespace eosdac {
void setMsigAuths(name dac_id);
void transferCustodianBudget(const dacdir::dac &dac);
void removeCustodian(name cust, name internal_dac_id);
void removeCandidate(name cust, bool lockupStake, name internal_dac_id);
void disableCandidate(name cust, name internal_dac_id);
void removeCandidate(name cust, name internal_dac_id);
void allocateCustodians(bool early_election, name internal_dac_id);
bool permissionExists(name account, name permission);
bool _check_transaction_authorization(const char *trx_data, uint32_t trx_size, const char *pubkeys_data,
Expand Down
45 changes: 23 additions & 22 deletions contracts/TestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class SharedTestObjects {
private async initAndGetSharedObjects() {
console.log('Init eos blockchain');
await sleep(1000);
await this.configTokenContract();

// EOSManager.initWithDefaults();

this.auth_account = await debugPromise(
Expand All @@ -79,27 +81,6 @@ export class SharedTestObjects {
'create treasury account'
);

await EOSManager.transact({
actions: [
{
account: 'eosio.token',
name: 'transfer',
authorization: [
{
actor: 'eosio',
permission: 'active',
},
],
data: {
from: 'eosio',
to: 'treasury',
quantity: '1000.0000 EOS',
memo: 'Some money for the treasury',
},
},
],
});

// Configure Dac contracts
this.dacdirectory_contract = await ContractDeployer.deployWithName(
'dacdirectory',
Expand Down Expand Up @@ -146,9 +127,29 @@ export class SharedTestObjects {
this.activation_account = await AccountManager.createAccount('activation');
// Other objects
this.configured_dac_memberterms = 'be2c9d0494417cf7522cd8d6f774477c';
await this.configTokenContract();
await this.add_auth_account_permissions();
await this.add_token_contract_permissions();

await EOSManager.transact({
actions: [
{
account: 'eosio.token',
name: 'transfer',
authorization: [
{
actor: 'eosio',
permission: 'active',
},
],
data: {
from: 'eosio',
to: 'treasury',
quantity: '1000.0000 EOS',
memo: 'Some money for the treasury',
},
},
],
});
}

async setup_new_auth_account() {
Expand Down
221 changes: 208 additions & 13 deletions contracts/daccustodian/daccustodian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,9 @@ describe('Daccustodian', () => {
context(
'with enough elected candidates to replace a removed candidate',
async () => {
let electedCandidateToResign: Account;
before(async () => {
electedCandidateToResign = existing_candidates[3];
await debugPromise(
shared.daccustodian_contract.votecust(
regMembers[14].name,
Expand All @@ -2088,9 +2090,7 @@ describe('Daccustodian', () => {
'voting for an extra candidate'
);
});
it('should succeed with lockup of stake', async () => {
let electedCandidateToResign = existing_candidates[3];

it('should succeed', async () => {
await shared.daccustodian_contract.resigncust(
electedCandidateToResign.name,
dacId,
Expand All @@ -2104,13 +2104,18 @@ describe('Daccustodian', () => {
],
}
);
let candidates =
await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToResign.name,
upperBound: electedCandidateToResign.name,
});
});
it('should disable candidate', async () => {
const res = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToResign.name,
upperBound: electedCandidateToResign.name,
});
chai
.expect(res.rows[0].candidate_name)
.to.equal(electedCandidateToResign.name);
chai.expect(res.rows[0].is_active).to.equal(0);
});
}
);
Expand Down Expand Up @@ -2185,18 +2190,38 @@ describe('Daccustodian', () => {
});
context('with correct auth', async () => {
context('for a currently elected custodian', async () => {
it('should succeed with lockup of stake active from previous election', async () => {
it('before, candidate should be active', async () => {
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToResign.name,
upperBound: electedCandidateToResign.name,
});
const cand = candidates.rows[0];
chai
.expect(cand.candidate_name)
.to.equal(electedCandidateToResign.name);
chai.expect(cand.is_active).to.equal(1);
});
it('should succeed', async () => {
await shared.daccustodian_contract.withdrawcane(
electedCandidateToResign.name,
dacId,
{ from: electedCandidateToResign }
);
});
it('should disable candidate', async () => {
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToResign.name,
upperBound: electedCandidateToResign.name,
});
const cand = candidates.rows[0];
chai
.expect(cand.candidate_name)
.to.equal(electedCandidateToResign.name);
chai.expect(cand.is_active).to.equal(0);
});
});
context('for an unelected candidate', async () => {
Expand Down Expand Up @@ -2248,6 +2273,154 @@ describe('Daccustodian', () => {
});
});
});
context('removecand', () => {
let dacId = 'removecdac';
let unelectedCandidateToResign: Account;
let electedCandidateToResign: Account;
let unregisteredCandidate: Account;

before(async () => {
await shared.initDac(dacId, '4,REMDAC', '1000000.0000 REMDAC');
await shared.updateconfig(dacId, '12.0000 REMDAC');
await shared.dac_token_contract.stakeconfig(
{ enabled: true, min_stake_time: 5, max_stake_time: 20 },
'4,REMDAC',
{ from: shared.auth_account }
);

let regMembers = await shared.getRegMembers(dacId, '20000.0000 REMDAC');
unregisteredCandidate = regMembers[0];
let candidates = await shared.getStakeObservedCandidates(
dacId,
'12.0000 REMDAC',
NUMBER_OF_CANDIDATES + 1
);
await shared.voteForCustodians(regMembers, candidates, dacId);
await shared.daccustodian_contract.newperiod(
'initial new period',
dacId,
{
from: regMembers[0], // Could be run by anyone.
}
);
electedCandidateToResign = candidates[3];
unelectedCandidateToResign = candidates[NUMBER_OF_CANDIDATES];
});
it('should fail for unregistered candidate with not current candidate error', async () => {
await assertEOSErrorIncludesMessage(
shared.daccustodian_contract.removecand(
unregisteredCandidate.name,
dacId,
{ from: unregisteredCandidate }
),
'REMOVECANDIDATE_NOT_CURRENT_CANDIDATE'
);
});
it('should fail with incorrect auth returning auth error', async () => {
await assertMissingAuthority(
shared.daccustodian_contract.removecand(
unregisteredCandidate.name,
dacId,
{ from: unelectedCandidateToResign }
)
);
});
context('with correct auth', async () => {
context('for a currently elected custodian', async () => {
it('before, candidate should be active', async () => {
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToResign.name,
upperBound: electedCandidateToResign.name,
});
const cand = candidates.rows[0];
chai
.expect(cand.candidate_name)
.to.equal(electedCandidateToResign.name);
chai.expect(cand.is_active).to.equal(1);
});
it('should fail with REMOVECANDIDATE_CANDIDATE_IS_ACTIVE error', async () => {
await assertEOSErrorIncludesMessage(
shared.daccustodian_contract.removecand(
electedCandidateToResign.name,
dacId,
{ from: electedCandidateToResign }
),
'REMOVECANDIDATE_CANDIDATE_IS_ACTIVE'
);
});
it('after withdrawing, should work', async () => {
await shared.daccustodian_contract.withdrawcane(
electedCandidateToResign.name,
dacId,
{ from: electedCandidateToResign }
);
await shared.daccustodian_contract.removecand(
electedCandidateToResign.name,
dacId,
{ from: electedCandidateToResign }
);
});
it('should remove candidate table entry', async () => {
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToResign.name,
upperBound: electedCandidateToResign.name,
});
chai.expect(candidates.rows).to.be.empty;
});
});
context('for an unelected candidate', async () => {
before(async () => {
await shared.daccustodian_contract.withdrawcane(
unelectedCandidateToResign.name,
dacId,
{ from: unelectedCandidateToResign }
);
});
it('should succeed and not change the number of active candidates', async () => {
let numberActiveCandidatesBefore = await get_from_dacglobals(
dacId,
'number_active_candidates'
);

await shared.daccustodian_contract.removecand(
unelectedCandidateToResign.name,
dacId,
{ from: unelectedCandidateToResign }
);
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: unelectedCandidateToResign.name,
upperBound: unelectedCandidateToResign.name,
});

chai.expect(candidates.rows).to.be.empty;

var numberActiveCandidatesAfter = await get_from_dacglobals(
dacId,
'number_active_candidates'
);
chai
.expect(numberActiveCandidatesAfter)
.to.be.equal(numberActiveCandidatesBefore);
});
it('removing the same candidate twice should fail', async () => {
await assertEOSErrorIncludesMessage(
shared.daccustodian_contract.removecand(
unelectedCandidateToResign.name,
dacId,
{ from: unelectedCandidateToResign }
),
'ERR::REMOVECANDIDATE_NOT_CURRENT_CANDIDATE'
);
});
});
});
});
context('fire candidate', () => {
let dacId = 'firedac';
let unelectedCandidateToFire: Account;
Expand Down Expand Up @@ -2311,12 +2484,16 @@ describe('Daccustodian', () => {
dacId,
{ from: shared.auth_account }
);
});

it('should delete candidate table entries', async () => {
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToFire.name,
upperBound: electedCandidateToFire.name,
});
chai.expect(candidates.rows).to.be.empty;
});
});
context('for an unelected candidate', async () => {
Expand All @@ -2339,7 +2516,7 @@ describe('Daccustodian', () => {
upperBound: unelectedCandidateToFire.name,
});

chai.expect(candidates.rows[0].is_active).to.be.equal(0);
chai.expect(candidates.rows).to.be.empty;

var numberActiveCandidatesAfter = await get_from_dacglobals(
dacId,
Expand Down Expand Up @@ -2416,7 +2593,7 @@ describe('Daccustodian', () => {
'voting for an extra candidate'
);
});
it('should succeed with lockup of stake', async () => {
it('should succeed', async () => {
await shared.daccustodian_contract.firecust(
electedCandidateToFire.name,
dacId,
Expand All @@ -2429,6 +2606,24 @@ describe('Daccustodian', () => {
upperBound: electedCandidateToFire.name,
});
});
it('should delete custodian table entry', async () => {
const res = await shared.daccustodian_contract.custodiansTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToFire.name,
upperBound: electedCandidateToFire.name,
});
chai.expect(res.rows).to.be.empty;
});
it('should delete candidate table entry', async () => {
let candidates = await shared.daccustodian_contract.candidatesTable({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToFire.name,
upperBound: electedCandidateToFire.name,
});
chai.expect(candidates.rows).to.be.empty;
});
});
context('for an unelected candidate', async () => {
it('should fail with not current custodian error', async () => {
Expand Down
Loading

0 comments on commit 3c36a11

Please sign in to comment.