Skip to content

Commit

Permalink
Merge pull request #46 from Alien-Worlds/CU-2tzhu89_Fix-referendum-co…
Browse files Browse the repository at this point in the history
…ntract-to-work-with-recent-change-to-msigworlds

Cu 2tzhu89 fix referendum contract to work with recent change to msigworlds
  • Loading branch information
angelol authored Sep 16, 2022
2 parents 2450edf + 280018d commit 7fbe33a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
13 changes: 13 additions & 0 deletions contracts/TestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ export class SharedTestObjects {
key: Account_type.TREASURY,
value: this.treasury_account.name,
},
{
key: Account_type.REFERENDUM,
value: this.referendum_contract.account.name,
},
];
if (config && config.planet) {
accounts.push({
Expand Down Expand Up @@ -561,6 +565,14 @@ export class SharedTestObjects {
'notify'
);

await UpdateAuth.execLinkAuth(
this.dac_token_contract.account.active,
this.dac_token_contract.account.name,
this.referendum_contract.account.name,
'stakeobsv',
'notify'
);

await UpdateAuth.execLinkAuth(
this.dac_token_contract.account.active,
this.dac_token_contract.account.name,
Expand Down Expand Up @@ -917,6 +929,7 @@ export enum Account_type {
PROPOSALS = 6,
ESCROW = 7,
VOTING = 8,
REFERENDUM = 10,
EXTERNAL = 254,
OTHER = 255,
}
Expand Down
8 changes: 0 additions & 8 deletions contracts/daccustodian/daccustodian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Daccustodian', () => {
scope: dacId,
});
const s = res.rows[0];
console.log('s:', JSON.stringify(s, null, 2));
chai.expect(s.data).to.deep.equal([
{
key: 'auth_threshold_high',
Expand Down Expand Up @@ -488,7 +487,6 @@ describe('Daccustodian', () => {
scope: dacId,
limit: 1,
});
console.log(JSON.stringify(resx, null, 2));
await assertRowsEqual(
shared.daccustodian_contract.dacglobalsTable({
scope: dacId,
Expand Down Expand Up @@ -921,7 +919,6 @@ describe('Daccustodian', () => {
let dacState = await shared.daccustodian_contract.dacglobalsTable({
scope: dacId,
});
console.log('dacState: ', JSON.stringify(dacState, null, 2));
chai.expect(dacState.rows[0].data).to.deep.include({
key: 'total_weight_of_votes',
value: ['int64', 0],
Expand Down Expand Up @@ -2635,9 +2632,6 @@ describe('Daccustodian', () => {
});
});
it('should only transfer treasury balance', async () => {
console.log('treasury_balance_before: ', treasury_balance_before);
console.log('auth_balance_before: ', auth_balance_before);
console.log('expected_transfer_amount: ', expected_transfer_amount);
const expected_treasury_balance_after =
treasury_balance_before - expected_transfer_amount;
const expected_auth_balance_after =
Expand Down Expand Up @@ -2939,8 +2933,6 @@ async function getTemplateId(schema_name: string, name: string) {
const atomic = get_atomic();
const templates = await atomic.getCollectionTemplates(NFT_COLLECTION);
const objects = await Promise.all(templates.map((x) => x.toObject()));
console.log(`getTemplateId schema_name: ${schema_name} name: ${name}`);
console.log(JSON.stringify(objects, null, 2));
return parseInt(
objects.find((x) => {
return (
Expand Down
1 change: 0 additions & 1 deletion contracts/dacproposals/dacproposals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,6 @@ describe('Dacproposals', () => {

async function setup_test_user(testuser: Account, tokenSymbol: string) {
// const testuser = await AccountManager.createAccount('clienttest');
console.log(`testuser: ${JSON.stringify(testuser, null, 2)}`);
await shared.dac_token_contract.transfer(
shared.dac_token_contract.account.name,
testuser.name,
Expand Down
4 changes: 1 addition & 3 deletions contracts/msigworlds/msigworlds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "msigworlds.hpp"

#include "../../contract-shared-headers/eosdactokens_shared.hpp"

using namespace eosio;

transaction_header get_trx_header(const char *ptr, size_t sz);
Expand Down Expand Up @@ -36,7 +34,7 @@ std::vector<permission_level> get_approvals_and_adjust_table(
void multisig::propose(name proposer, name proposal_name, std::vector<permission_level> requested, name dac_id,
std::map<std::string, std::string> metadata, ignore<transaction> trx) {
require_auth(proposer);
eosdac::assertValidMember(proposer, dac_id);
assertValidMember(proposer, dac_id);
auto &ds = get_datastream();

const char *trx_pos = ds.pos();
Expand Down
16 changes: 16 additions & 0 deletions contracts/msigworlds/msigworlds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <eosio/singleton.hpp>
#include <eosio/transaction.hpp>

#include "../../contract-shared-headers/dacdirectory_shared.hpp"
#include "../../contract-shared-headers/eosdactokens_shared.hpp"

using namespace eosio;

enum PropState { PENDING = 0, EXECUTED = 1, CANCELLED = 2 };
Expand Down Expand Up @@ -235,4 +238,17 @@ class [[eosio::contract("msigworlds")]] multisig : public eosio::contract {
private:
uint64_t next_id(name dac_id);
void _unapprove(name proposal_name, permission_level level, name dac_id, bool throw_if_not_previously_approved);

void assertValidMember(const name proposer, const name dac_id) {
const auto dac = eosdac::dacdir::dac_for_id(dac_id);
const auto referendum_contract = dac.account_for_type_maybe(eosdac::dacdir::REFERENDUM);

if (referendum_contract) {
if (proposer != *referendum_contract) {
eosdac::assertValidMember(proposer, dac_id);
}
} else {
eosdac::assertValidMember(proposer, dac_id);
}
}
};
2 changes: 1 addition & 1 deletion contracts/msigworlds/msigworlds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('msigworlds', () => {

context('with correct auth', async () => {
context('from unregistered member', async () => {
it('should fail with expired error', async () => {
it('should fail with member not found error', async () => {
await assertEOSErrorIncludesMessage(
msigworlds.propose(
owner1.name,
Expand Down

0 comments on commit 7fbe33a

Please sign in to comment.