Skip to content

Commit

Permalink
Merge pull request #99 from Alien-Worlds/merge-everything
Browse files Browse the repository at this point in the history
Merge everything
  • Loading branch information
angelol authored Dec 6, 2022
2 parents ffb33d4 + 301c826 commit ec7e9b3
Show file tree
Hide file tree
Showing 12 changed files with 1,184 additions and 25 deletions.
6 changes: 3 additions & 3 deletions contract-shared-headers/daccustodian_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace eosdac {
#ifndef TRANSFER_DELAY
#define TRANSFER_DELAY 60 * 60
#endif
struct [[eosio::table("custodians"), eosio::contract("daccustodian")]] custodian {
struct [[eosio::table("custodians1"), eosio::contract("daccustodian")]] custodian {
eosio::name cust_name;
eosio::asset requestedpay;
uint64_t total_vote_power;
Expand All @@ -55,7 +55,7 @@ namespace eosdac {
}
};

using custodians_table = eosio::multi_index<"custodians"_n, custodian,
using custodians_table = eosio::multi_index<"custodians1"_n, custodian,
eosio::indexed_by<"byvotesrank"_n, eosio::const_mem_fun<custodian, uint64_t, &custodian::by_votes_rank>>,
eosio::indexed_by<"bydecayed"_n, eosio::const_mem_fun<custodian, uint64_t, &custodian::by_decayed_votes>>,
eosio::indexed_by<"byreqpay"_n, eosio::const_mem_fun<custodian, uint64_t, &custodian::by_requested_pay>>>;
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace eosdac {
#ifdef DEBUG
ACTION migratestate(const name &dac_id);
ACTION resetvotes(const name &voter, const name &dac_id);
ACTION collectvotes(const name &dac_id);
ACTION collectvotes(const name &dac_id, name from, name to);
ACTION resetcands(const name &dac_id);
ACTION resetstate(const name &dac_id);
ACTION clearcands(const name &dac_id);
Expand Down
2 changes: 1 addition & 1 deletion contract-shared-headers/safemath
14 changes: 13 additions & 1 deletion contracts/TestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as chai from 'chai';

import * as fs from 'fs';
import * as path from 'path';
import { rename, stat } from 'node:fs/promises';

export var NUMBER_OF_CANDIDATES = 7;

Expand Down Expand Up @@ -89,6 +90,7 @@ export class SharedTestObjects {
'dacdirectory',
'index.worlds'
);

this.daccustodian_contract = await debugPromise(
ContractDeployer.deployWithName('daccustodian', 'daccustodian'),
'created daccustodian'
Expand Down Expand Up @@ -925,7 +927,7 @@ export class SharedTestObjects {
// Not used for now but could be useful later
async function setup_external(name: string) {
const compiled_dir = path.normalize(
`${__dirname}/../artifacts/compiled_contracts/${name}`
`${__dirname}/./compiled_contracts/${name}`
);

if (!fs.existsSync(compiled_dir)) {
Expand Down Expand Up @@ -975,3 +977,13 @@ enum dac_state_type {
dac_state_typeINACTIVE = 0,
dac_state_typeACTIVE = 1,
}

// returns true if file exists, false otherwise
async function fileExists(path: string) {
try {
await stat(path);
return true;
} catch (err) {
return false;
}
}
21 changes: 9 additions & 12 deletions contracts/daccustodian/daccustodian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TableRowsResult,
assertBalanceEqual,
Asset,
ContractDeployer,
} from 'lamington';
const _ = require('lodash');
import {
Expand Down Expand Up @@ -403,7 +404,6 @@ describe('Daccustodian', () => {
}),
[
{
serial: 1,
data: [
{
key: 'auth_threshold_high',
Expand Down Expand Up @@ -636,7 +636,6 @@ describe('Daccustodian', () => {
const result = await shared.daccustodian_contract.dacglobalsTable({
scope: dacId,
});
console.log('serial: ' + result.rows[0].serial);
await shared.daccustodian_contract.nominatecane(
newUser1.name,
'25.0000 EOS',
Expand Down Expand Up @@ -1611,7 +1610,7 @@ describe('Daccustodian', () => {
);

await assertRowCount(
shared.daccustodian_contract.custodiansTable({
shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 20,
}),
Expand All @@ -1637,7 +1636,7 @@ describe('Daccustodian', () => {
keyType: 'i64',
});

let res2 = await shared.daccustodian_contract.custodiansTable({
let res2 = await shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 100,
indexPosition: 2, // bydecayed index
Expand Down Expand Up @@ -1683,7 +1682,7 @@ describe('Daccustodian', () => {
);

const custodians =
await shared.daccustodian_contract.custodiansTable({
await shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 20,
});
Expand Down Expand Up @@ -1935,7 +1934,7 @@ describe('Daccustodian', () => {
});
it('custodians should the mean pay from the valid requested pays. (Requested pay exceeding the max pay should be ignored from the mean.)', async () => {
let custodianRows =
await shared.daccustodian_contract.custodiansTable({
await shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 12,
});
Expand Down Expand Up @@ -2688,7 +2687,7 @@ describe('Daccustodian', () => {
});
});
it('should delete custodian table entry', async () => {
const res = await shared.daccustodian_contract.custodiansTable({
const res = await shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 20,
lowerBound: electedCandidateToFire.name,
Expand Down Expand Up @@ -2842,7 +2841,7 @@ describe('Daccustodian', () => {
chai.expect(candidates.rows[0].number_voters).to.equal(0);
chai.expect(candidates.rows[0].is_active).to.equal(1);

let custodians = await shared.daccustodian_contract.custodiansTable({
let custodians = await shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 20,
});
Expand Down Expand Up @@ -3593,9 +3592,7 @@ async function get_expected_avg_vote_time_stamp(
avg_vote_time_stamp = new Date(0);
} else {
const delta_milliseconds =
(Math.abs(
ourvote.vote_time_stamp.getTime() - avg_vote_time_stamp.getTime()
) *
((ourvote.vote_time_stamp.getTime() - avg_vote_time_stamp.getTime()) *
(-1 * vote_weight)) /
total_vote_power;
let new_milliseconds = Math.floor(
Expand All @@ -3607,7 +3604,7 @@ async function get_expected_avg_vote_time_stamp(
}
total_vote_power += vote_weight;
const delta_milliseconds =
(Math.abs(now.getTime() - avg_vote_time_stamp.getTime()) * vote_weight) /
((now.getTime() - avg_vote_time_stamp.getTime()) * vote_weight) /
total_vote_power;
let new_milliseconds = Math.floor(
avg_vote_time_stamp.getTime() + delta_milliseconds
Expand Down
6 changes: 3 additions & 3 deletions contracts/daccustodian/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ void daccustodian::resetvotes(const name &voter, const name &dac_id) {
check(existingVote != votes_cast_by_members.end(), "No votes");
}

void daccustodian::collectvotes(const name &dac_id) {
void daccustodian::collectvotes(const name &dac_id, name from, name to) {
require_auth(get_self());

votes_table votes_cast_by_members(_self, dac_id.value);
auto vote_ittr = votes_cast_by_members.begin();
auto vote_ittr = votes_cast_by_members.lower_bound(from.value);

while (vote_ittr != votes_cast_by_members.end()) {
while (vote_ittr != votes_cast_by_members.end() && vote_ittr->voter != to) {
update_number_of_votes({}, vote_ittr->candidates, dac_id);
const auto [vote_weight, vote_weight_quorum] = get_vote_weight(vote_ittr->voter, dac_id);
modifyVoteWeights({vote_ittr->voter, vote_weight, vote_weight_quorum}, {}, {}, vote_ittr->candidates,
Expand Down
2 changes: 1 addition & 1 deletion contracts/daccustodian/privatehelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ time_point_sec daccustodian::calculate_avg_vote_time_stamp(const time_point_sec

const auto initial = S{vote_time_before.sec_since_epoch()}.to<int128_t>();
const auto current = S{vote_time_stamp.sec_since_epoch()}.to<int128_t>();
const auto time_delta = (current - initial).abs();
const auto time_delta = (current - initial);
const auto new_seconds = initial + time_delta * S{weight}.to<int128_t>() / S{total_votes}.to<int128_t>();

return time_point_sec{new_seconds.to<uint32_t>()};
Expand Down
1 change: 1 addition & 0 deletions contracts/daccustodian/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ACTION daccustodian::votecust(const name &voter, const vector<name> &newvotes, c
#ifndef IS_DEV
// check(dac_id == "testa"_n || dac_id == "testb"_n, "Voting is not yet enabled in the Planet DAOs.");
#endif

candidates_table registered_candidates(_self, dac_id.value);
const auto globals = dacglobals{get_self(), dac_id};

Expand Down
3 changes: 2 additions & 1 deletion contracts/dacproposals/dacproposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ namespace eosdac {
config configs = current_configs(dac_id);

check(approved_count >= configs.proposal_threshold,
"ERR::STARTWORK_INSUFFICIENT_VOTES::Insufficient votes on worker proposal.");
"ERR::STARTWORK_INSUFFICIENT_VOTES::Insufficient votes on worker proposal. Has %s but needs %s.",
approved_count, configs.proposal_threshold);
}

void dacproposals::arbitrator_rule_on_proposal(name arbitrator, name proposal_id, name dac_id) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/safemath/safemath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Safemath', () => {
it('uunderflow should throw invalid unsigned subtraction error', async () => {
await assertEOSErrorIncludesMessage(
contract.uunderflow(),
'invalid unsigned subtraction: result would be negative'
'invalid unsigned subtraction: uint64_t 1 - 2 result would be negative'
);
});
it('usdivzero should throw invalid unsigned subtraction error', async () => {
Expand Down
4 changes: 2 additions & 2 deletions contracts/stakevote/stakevote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ describe('Stakevote', () => {
);

await assertRowCount(
shared.daccustodian_contract.custodiansTable({
shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 20,
}),
Expand All @@ -341,7 +341,7 @@ describe('Stakevote', () => {
});
it('Should have highest ranked votes in custodians', async () => {
let rowsResult =
await shared.daccustodian_contract.custodiansTable({
await shared.daccustodian_contract.custodians1Table({
scope: dacId,
limit: 14,
indexPosition: 2,
Expand Down
Loading

0 comments on commit ec7e9b3

Please sign in to comment.