Skip to content

Commit

Permalink
fix(resolver): add failing test when using multiAttest with a Score a…
Browse files Browse the repository at this point in the history
…ttestation
  • Loading branch information
nutrina committed Dec 4, 2023
1 parent 96d1176 commit e129253
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions test/GitcoinResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,26 @@ describe("GitcoinResolver", function () {
nonOwnerOrVerifier: any,
mockEas: any,
gitcoinResolver: GitcoinResolver,
gitcoinAttester: GitcoinAttester;
gitcoinAttester: GitcoinAttester,
recipients: string[],
nextRecipientIndex: number = 0;

before(async function () {
const [
ownerAccount,
otherAccount,
recipientAccount,
mockEasContractAccount,
nonOwnerOrVerifierAccount
nonOwnerOrVerifierAccount,
...moreSigners
] = await ethers.getSigners();

owner = ownerAccount;
iamAccount = otherAccount;
recipient = recipientAccount;
mockEas = mockEasContractAccount;
nonOwnerOrVerifier = nonOwnerOrVerifierAccount;
recipients = moreSigners.map((signer) => signer.address);

const GitcoinAttester = await ethers.getContractFactory(
"GitcoinAttester",
Expand Down Expand Up @@ -171,12 +175,18 @@ describe("GitcoinResolver", function () {
});
});

describe("Caching Scores", function () {
describe.only("Caching Scores", function () {
let recipient: string;

this.beforeEach(async function () {
recipient = recipients[nextRecipientIndex++];
});

it("should cache a score and properly reduce the number of decimals when there are more than 4", async function () {
const attestation = getScoreAttestation(
{
schema: this.scoreSchemaId,
recipient: recipient.address,
recipient: recipient,
attester: this.gitcoinAttesterAddress
},
{
Expand All @@ -193,7 +203,7 @@ describe("GitcoinResolver", function () {
.attest(attestation);
const attestReceipt = attestRequest.wait();

const score = await gitcoinResolver.getCachedScore(recipient.address);
const score = await gitcoinResolver.getCachedScore(recipient);

// Score should have been casted to a 4 digit value
expect(score[0]).to.equal("123456");
Expand All @@ -205,7 +215,7 @@ describe("GitcoinResolver", function () {
const attestation = getScoreAttestation(
{
schema: this.scoreSchemaId,
recipient: recipient.address,
recipient: recipient,
attester: this.gitcoinAttesterAddress
},
{
Expand All @@ -222,7 +232,7 @@ describe("GitcoinResolver", function () {
.attest(attestation);
const attestReceipt = attestRequest.wait();

const score = await gitcoinResolver.getCachedScore(recipient.address);
const score = await gitcoinResolver.getCachedScore(recipient);

// Score should have been casted to a 4 digit value
expect(score[0]).to.equal("123400");
Expand Down Expand Up @@ -251,13 +261,37 @@ describe("GitcoinResolver", function () {
.attest(attestation);
const attestReceipt = attestRequest.wait();

const score = await gitcoinResolver.getCachedScore(recipient.address);
const score = await gitcoinResolver.getCachedScore(recipient);

// Score should have been casted to a 4 digit value
expect(score[0]).to.equal("123456");
expect(score[1]).to.equal("200500");
expect(score[2]).to.equal("700500");
});

it("should cache a score from an attestation that is part of a multiAttest call", async function () {
const attestation = getScoreAttestation(
{
schema: this.scoreSchemaId,
recipient: recipient,
attester: this.gitcoinAttesterAddress
},
{
score: "98765", // That is 12.34 (2 decimals)
scorer_id: 3,
score_decimals: 4
}
) as AttestationStruct;

await gitcoinResolver
.connect(mockEas)
.multiAttest([this.validAttestation, attestation], []);

const score = await gitcoinResolver.getCachedScore(recipient);

// Score should have been casted to a 4 digit value
expect(score[0]).to.equal("98765");
});
});

describe("Revocations", function () {
Expand Down

0 comments on commit e129253

Please sign in to comment.