The TestCredentialarrow-up-right object abstracts most of the Block Qualified logic away, allowing you to easily interact with the protocol. It incorporates an OpenZeppelin Autotaskarrow-up-right for a transaction relayerarrow-up-right , making it easier to onboard users.
Defining a TestCredential Object
You can define a new TestCredential object with the following syntax:
Copy const testCredential = await TestCredential .init (
credentialId ,
{
provider : "provider" ,
apiKey : process . env . PROVIDER_KEY
} ,
"network" ,
openAnswersHashes
) circle-exclamation
The value for openAnswersHashes needs to be provided for tests that implement an open answers component, as defined for Block Qualified tests
Grading a Solution to a Test
Once initialized, you can use the TestCredential object to grade solutions to the test:
Copy const result = testCredential .gradeSolution ({ multipleChoiceAnswers , openAnswers }) Where result will be an object containing the following values:
grade: over 100, grade obtained in the test.
minimumGrade: over 100, minimum grade needed to pass the test.
pass: whether the test was passed or not.
nQuestions: number of open answer questions that make up this test.
multipleChoiceGrade: grade obtained in the multiple choice component of this test.
openAnswerGrade: grade obtained in the open answer component of this test.
multipleChoiceWeight: percentage that the multiple choice component contributes towards the final grade.
openAnswerResults array containing boolean values indicating the result for each open answer question.
Generating and Verifying a Solution Proof
You can generate a test solution proof as described in Block Qualified Proofs by calling:
Where the value for identity is a valid Semaphore identityarrow-up-right that is then added to a given group, as described in the Block Qualified contracts .
You can then verify this proof by calling:
Which will return true or false.
Sending a Solution Transaction
You can use the implemented OpenZeppelin Relayerarrow-up-right to send this transaction free of gas.
Generating and Verifying a Rating Proof
You can generate a rating proof as described in Rating the Credential Issuer by calling:
Where the value for identity is a valid Semaphore identityarrow-up-right that must have already gained this test credential.
You can then verify this proof by calling:
Which will return true or false.
Sending a Rating Transaction
You can use the implemented OpenZeppelin Relayerarrow-up-right to send this transaction free of gas.