Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 90f1af1

Browse files
committed
add decrease scores
1 parent 1a27446 commit 90f1af1

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function handleUpdateScores (req, res, redis, signerAddress) {
5858
)
5959

6060
const digest = ethers.solidityPackedKeccak256(
61-
['address[]', 'uint256[]'],
61+
['address[]', 'int256[]'],
6262
[Object.keys(body.scores), Object.values(body.scores)]
6363
)
6464
const reqSigner = ethers.verifyMessage(

test.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test('scores', async t => {
4545
}
4646
{
4747
const digest = ethers.solidityPackedKeccak256(
48-
['address[]', 'uint256[]'],
48+
['address[]', 'int256[]'],
4949
[['0x000000000000000000000000000000000000dEaD'], ['1']]
5050
)
5151
const signed = await signer.signMessage(digest)
@@ -73,7 +73,7 @@ test('scores', async t => {
7373
}
7474
{
7575
const digest = ethers.solidityPackedKeccak256(
76-
['address[]', 'uint256[]'],
76+
['address[]', 'int256[]'],
7777
[['0x000000000000000000000000000000000000dEaD'], ['1']]
7878
)
7979
const signed = await signer.signMessage(digest)
@@ -99,10 +99,38 @@ test('scores', async t => {
9999
'0x000000000000000000000000000000000000dEaD': '2'
100100
})
101101
}
102+
{
103+
const digest = ethers.solidityPackedKeccak256(
104+
['address[]', 'int256[]'],
105+
[['0x000000000000000000000000000000000000dEaD'], ['-2']]
106+
)
107+
const signed = await signer.signMessage(digest)
108+
const { v, r, s } = ethers.Signature.from(signed)
109+
const res = await fetch(`${api}/scores`, {
110+
method: 'POST',
111+
body: JSON.stringify({
112+
scores: {
113+
'0x000000000000000000000000000000000000dEaD': '-2'
114+
},
115+
signature: {
116+
v,
117+
r,
118+
s
119+
}
120+
})
121+
})
122+
assert.strictEqual(res.status, 200)
123+
}
124+
{
125+
const res = await fetch(`${api}/scores`)
126+
assert.deepEqual(await res.json(), {
127+
'0x000000000000000000000000000000000000dEaD': '0'
128+
})
129+
}
102130
})
103131
await t.test('validate signatures', async t => {
104132
const digest = ethers.solidityPackedKeccak256(
105-
['address[]', 'uint256[]'],
133+
['address[]', 'int256[]'],
106134
[['0x000000000000000000000000000000000000dEaD'], ['2']]
107135
)
108136
const signed = await signer.signMessage(digest)

0 commit comments

Comments
 (0)