Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketpatil8824 authored Mar 9, 2023
2 parents d152914 + d76a688 commit 5477f50
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 1,805 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/snapshot.js",
"version": "0.4.65",
"version": "0.4.68",
"repository": "snapshot-labs/snapshot.js",
"license": "MIT",
"main": "dist/snapshot.cjs.js",
Expand Down
4 changes: 4 additions & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
"testnet": {
"hub": "https://testnet.snapshot.org",
"sequencer": "https://testnet.seq.snapshot.org"
},
"local": {
"hub": "http://localhost:3000",
"sequencer": "http://localhost:3001"
}
}
5 changes: 3 additions & 2 deletions src/sign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ export default class Client {

constructor(address: string = constants.livenet.sequencer) {
address = address.replace(
'https://hub.snapshot.org',
constants.livenet.hub,
constants.livenet.sequencer
);
address = address.replace(
'https://testnet.snapshot.org',
constants.testnet.hub,
constants.testnet.sequencer
);
address = address.replace(constants.local.hub, constants.local.sequencer);
this.address = address;
}

Expand Down
16 changes: 2 additions & 14 deletions src/voting/approval.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const example2 = () => {
[139, 139, 139],
[125, 125, 125]
];
const scoresTotal = 1161;
const scoresTotal = 1218;
const votes = example.votes.map((vote) => ({
choice: vote.choice,
balance: 3,
Expand Down Expand Up @@ -57,7 +57,7 @@ const rndChoices = () => {
rndNumber(),
rndNumber()
];
return Math.random() < 0.9 ? choices : [];
return choices;
};

const votesWithInvalidChoices = () => {
Expand Down Expand Up @@ -161,23 +161,11 @@ test.each(getScoresByStrategyTests)(

const getScoresTotalTests = [
[example.proposal, example.votes, example.strategies, example.scoresTotal],
[
example.proposal,
votesWithInvalidChoices(),
example.strategies,
example.scoresTotal
],
[
example2().proposal,
example2().votes,
example2().strategies,
example2().scoresTotal
],
[
example2().proposal,
votesWithInvalidChoices2(),
example2().strategies,
example2().scoresTotal
]
];

Expand Down
6 changes: 2 additions & 4 deletions src/voting/approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export default class ApprovalVoting {
(choice) => proposalChoices?.[choice - 1] !== undefined
) &&
// If any voteChoice is duplicated, return false
voteChoice.length === new Set(voteChoice).size &&
// If voteChoice is empty, return false
voteChoice.length > 0
voteChoice.length === new Set(voteChoice).size
);
}

Expand Down Expand Up @@ -64,7 +62,7 @@ export default class ApprovalVoting {
}

getScoresTotal(): number {
return this.getValidVotes().reduce((a, b) => a + b.balance, 0);
return this.votes.reduce((a, b) => a + b.balance, 0);
}

getChoiceString(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/voting/examples/approval.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"strategies": [{ "name": "ticket", "network": 1, "params": {} }],
"scores": [257, 171, 139, 125],
"scoresByStrategy": [[257], [171], [139], [125]],
"scoresTotal": 387,
"scoresTotal": 406,
"selectedChoice": [1, 3],
"votes": [
{
Expand Down
Loading

0 comments on commit 5477f50

Please sign in to comment.