-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add permissioned versions of all Business Scenarios (#130)
* Update VeriteAccessControl contract to be abstract * Add missing @types/uuid * Add extra check with verite during helper * Add business scenario #1 test for Verite * Add business scenario 2 * Add Permissioned scenario 3 * Ensure permitted to request withdrawal/redeem as well * Add permissioned scenario 4 * Fix error message * Update permissioned scenario test names * Fix variable name in tests
- Loading branch information
Showing
14 changed files
with
1,374 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
import {VeriteAccessControl} from "../permissioned/VeriteAccessControl.sol"; | ||
|
||
contract MockVeriteAccessControl is VeriteAccessControl {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { ethers } from "hardhat"; | ||
import { getSignedVerificationResult } from "../support/verite"; | ||
import { expect } from "chai"; | ||
|
||
describe("VeriteAccessControl", () => { | ||
async function deployFixture() { | ||
const [verifier, admin, subject, otherSubject] = await ethers.getSigners(); | ||
|
||
const VeriteAccessControl = await ethers.getContractFactory( | ||
"MockVeriteAccessControl" | ||
); | ||
const veriteAccessControl = await VeriteAccessControl.deploy(); | ||
await veriteAccessControl.deployed(); | ||
|
||
return { | ||
veriteAccessControl, | ||
verifier, | ||
admin, | ||
subject, | ||
otherSubject | ||
}; | ||
} | ||
|
||
describe("verify()", () => { | ||
it("succeeds when given a valid verification result from a trusted verifier", async () => { | ||
const { veriteAccessControl, verifier, admin, subject } = | ||
await deployFixture(); | ||
|
||
// Register the verifier | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addTrustedVerifier(verifier.address); | ||
|
||
// Get a signed verification result | ||
const { verificationResult, signature } = | ||
await getSignedVerificationResult( | ||
veriteAccessControl.address, | ||
subject.address, | ||
verifier | ||
); | ||
|
||
// Register the schema | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addCredentialSchema(verificationResult.schema); | ||
|
||
// Verify the verification result | ||
await expect( | ||
veriteAccessControl | ||
.connect(subject) | ||
.verify(verificationResult, signature) | ||
) | ||
.to.emit(veriteAccessControl, "VerificationResultConfirmed") | ||
.withArgs(subject.address); | ||
}); | ||
|
||
it("reverts if the verifier is not trusted", async () => { | ||
const { veriteAccessControl, verifier, admin, subject } = | ||
await deployFixture(); | ||
|
||
// Get a signed verification result | ||
const { verificationResult, signature } = | ||
await getSignedVerificationResult( | ||
veriteAccessControl.address, | ||
subject.address, | ||
verifier | ||
); | ||
|
||
// Register the schema | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addCredentialSchema(verificationResult.schema); | ||
|
||
await expect( | ||
veriteAccessControl | ||
.connect(subject) | ||
.verify(verificationResult, signature) | ||
).to.be.revertedWith("INVALID_SIGNER"); | ||
}); | ||
|
||
it("reverts if the schema is not valid", async () => { | ||
const { veriteAccessControl, verifier, admin, subject } = | ||
await deployFixture(); | ||
|
||
// Register the verifier | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addTrustedVerifier(verifier.address); | ||
|
||
// Get a signed verification result | ||
const { verificationResult, signature } = | ||
await getSignedVerificationResult( | ||
veriteAccessControl.address, | ||
subject.address, | ||
verifier | ||
); | ||
|
||
// Verify the verification result | ||
await expect( | ||
veriteAccessControl | ||
.connect(subject) | ||
.verify(verificationResult, signature) | ||
).to.be.revertedWith("INVALID_CREDENTIAL_SCHEMA"); | ||
}); | ||
|
||
it("reverts if the subject does not match the sender", async () => { | ||
const { veriteAccessControl, verifier, admin, subject, otherSubject } = | ||
await deployFixture(); | ||
|
||
// Register the verifier | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addTrustedVerifier(verifier.address); | ||
|
||
// Get a signed verification result | ||
const { verificationResult, signature } = | ||
await getSignedVerificationResult( | ||
veriteAccessControl.address, | ||
subject.address, | ||
verifier | ||
); | ||
|
||
// Register the schema | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addCredentialSchema(verificationResult.schema); | ||
|
||
// Verify the verification result | ||
await expect( | ||
veriteAccessControl | ||
.connect(otherSubject) | ||
.verify(verificationResult, signature) | ||
).to.be.revertedWith("SUBJECT_MISMATCH"); | ||
}); | ||
|
||
it("reverts if the result is expired", async () => { | ||
const { veriteAccessControl, verifier, admin, subject } = | ||
await deployFixture(); | ||
|
||
// Register the verifier | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addTrustedVerifier(verifier.address); | ||
|
||
// Get a signed verification result | ||
const { verificationResult, signature } = | ||
await getSignedVerificationResult( | ||
veriteAccessControl.address, | ||
subject.address, | ||
verifier, | ||
{ expiration: 0 } | ||
); | ||
|
||
// Register the schema | ||
await veriteAccessControl | ||
.connect(admin) | ||
.addCredentialSchema(verificationResult.schema); | ||
|
||
// Verify the verification result | ||
await expect( | ||
veriteAccessControl | ||
.connect(subject) | ||
.verify(verificationResult, signature) | ||
).to.be.revertedWith("VERIFICATION_RESULT_EXPIRED"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.