Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Feat/unit tests (#3)
Browse files Browse the repository at this point in the history
* feat(unit-tests): started to add unit tests

* feat(unit-tests): added more unit tests

* feat(unit-tests): moved tests to their own file

* feat(unit-tests): restructured source code

* chore(): removed unused dependency
  • Loading branch information
godenzim authored and Juan Ignacio Rios committed Sep 28, 2022
1 parent c740b84 commit c8c92fa
Show file tree
Hide file tree
Showing 14 changed files with 1,725 additions and 1,049 deletions.
5 changes: 5 additions & 0 deletions pallets/acurast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ ecdsa-vendored = { package = "ecdsa_vendored", path = "p384/ecdsa", default-feat

[dev-dependencies]
base64 = { version = "0.13.0", default-features = false, features = ["alloc"] }
hex-literal = "0.3"

sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }

[features]
default = ["std"]
Expand Down
19 changes: 16 additions & 3 deletions pallets/acurast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Introduction

The Acurast Pallet allows a Parachain to integrate the Acurast functionality to be able to securly receive real world data posted by the Acurast Data Transmitters.
The Acurast Pallet allows a Parachain to integrate the Acurast functionality to be able to securly receive real world data posted by the Acurast Processors.

The Pallet exposes a number of extrinsic.

Expand All @@ -12,7 +12,7 @@ The Pallet exposes a number of extrinsic.
Allows the registration of a job. A registration consists of:

- An ipfs URL to a `script` (written in Javascript).
- The script will be run in the Acurast Trusted Virtual Machine that uses a Trusted Execution Environment (TEE) on the Acurast Data Transmitter.
- The script will be run in the Acurast Trusted Virtual Machine that uses a Trusted Execution Environment (TEE) on the Acurast Processor.
- An optional `allowedSources` list of allowed sources.
- A list of `AccountId`s that are allowed to `fulfill` the job. If no list is provided, all sources are accepted.
- An `allowOnlyVerifiedSources` boolean indicating if only verified source can fulfill the job.
Expand All @@ -38,6 +38,14 @@ Allows to post the fulfillment of a registered job. The fulfillment structure co

In addition to the `fulfillment` structure, `fulfill` expects the `AccountId` of the `requester` of the job.

### submitAttestation

Allows an Acurast Processor to submit a key attestation proving its integrity. The extrinsic parameter is a valid attestation certificate chain.

### updateCertificateRevocationList

Allows to update the certificate recovation list used during attestation validation.

## Setup

Add the following dependency to your Cargo manifest:
Expand Down Expand Up @@ -71,10 +79,15 @@ impl pallet_acurast::FulfillmentRouter<Runtime> for AcurastRouter {
}
}

parameter_types! {
pub AllowedRevocationListUpdate: Vec<AccountId> = vec![];
}

impl pallet_acurast::Config for Runtime {
type Event = Event;
type RegistrationExtra = AcurastRegistrationExtra;
type FulfillmentRouter = AcurastRouter;
type AllowedRevocationListUpdate = AllowedRevocationListUpdate;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down Expand Up @@ -219,7 +232,7 @@ contract SimpleFulfill {

## P256 signatures

Acurast Data Transmitters will sign extrinsics (the `fulfill` call) using a P256 (a.k.a secp256r1) private key.
Acurast Processors will sign extrinsics (the `fulfill` call) using a P256 (a.k.a secp256r1) private key.

By default, Substrate does not support the P256 curve. Use the `acurast-p256-crypto` crate to add support for P256 signature verification.

Expand Down
2 changes: 1 addition & 1 deletion pallets/acurast/p384/ecdsa/elliptic-curve/tests/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![cfg(all(feature = "dev", feature = "pkcs8"))]

use elliptic_curve::{
use elliptic_curve_vendored::{
dev::{PublicKey, SecretKey},
pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey},
sec1::ToEncodedPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![cfg(feature = "dev")]

use elliptic_curve::dev::SecretKey;
use elliptic_curve_vendored::dev::SecretKey;

#[test]
fn undersize_secret_key() {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
209 changes: 4 additions & 205 deletions pallets/acurast/src/attestation.rs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions pallets/acurast/src/attestation/asn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(all(feature = "alloc", not(feature = "std"), not(test)), no_std)]

use core::convert::TryInto;

use asn1::{
Asn1Read, Asn1Write, BitString, Enumerated, Null, ObjectIdentifier, SequenceOf, SetOf, Tlv,
};
Expand Down Expand Up @@ -84,6 +86,15 @@ pub enum Time {
GeneralizedTime(asn1::GeneralizedTime),
}

impl Time {
pub fn timestamp_millis(&self) -> u64 {
match self {
Time::UTCTime(time) => time.as_chrono().timestamp_millis().try_into().unwrap(),
Time::GeneralizedTime(time) => time.as_chrono().timestamp_millis().try_into().unwrap(),
}
}
}

#[derive(Asn1Read, Asn1Write, Clone)]
pub struct SubjectPublicKeyInfo<'a> {
pub algorithm: AlgorithmIdentifier<'a>,
Expand Down
Loading

0 comments on commit c8c92fa

Please sign in to comment.