Skip to content

Commit

Permalink
Feature/add ces version key (#9)
Browse files Browse the repository at this point in the history
* Set `ces_version` named key during initialization.
* Fix version number. It must be 1.1
  • Loading branch information
davidatwhiletrue committed Feb 20, 2023
1 parent 2118b31 commit 4b42b52
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.2.0] - 2023-02-20

## Changed
### Added

- Added `ces_version` named key to refer to the version of the CES in use.

### Changed

- `CLType::Any` is not supported anymore.
All parts of an event need to be `non-Any` `CLValue`s.
The check happens at the runtime in `to_bytes()` function.
`Any` causes problems to parse events in a generic
way because ofthe lack of a length indicator.
way because of the lack of a length indicator.

## [0.1.1] - 2023-02-13

Expand Down
5 changes: 4 additions & 1 deletion casper-event-standard/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{schema::Schemas, EVENTS_DICT, EVENTS_LENGTH, EVENTS_SCHEMA};
use crate::{
schema::Schemas, CES_VERSION, CES_VERSION_KEY, EVENTS_DICT, EVENTS_LENGTH, EVENTS_SCHEMA,
};
use alloc::string::ToString;
use casper_contract::contract_api::{runtime, storage};
use casper_contract::unwrap_or_revert::UnwrapOrRevert;
Expand All @@ -18,6 +20,7 @@ pub fn init(schemas: Schemas) {
storage::new_dictionary(EVENTS_DICT).unwrap_or_revert();
runtime::put_key(EVENTS_LENGTH, storage::new_uref(0u32).into());
runtime::put_key(EVENTS_SCHEMA, storage::new_uref(schemas).into());
runtime::put_key(CES_VERSION_KEY, storage::new_uref(CES_VERSION).into());
}

/// Emits an event.
Expand Down
4 changes: 4 additions & 0 deletions casper-event-standard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ pub const EVENTS_DICT: &str = "__events";
pub const EVENTS_LENGTH: &str = "__events_length";
/// The key under which the event schemas are stored.
pub const EVENTS_SCHEMA: &str = "__events_schema";
/// The key under which the ces version is stored.
pub const CES_VERSION_KEY: &str = "__events_ces_version";
/// The version of CES implemented in this library.
pub const CES_VERSION: &str = "1.1";

/// Helper trait, used for the schema generation.
pub trait EventInstance {
Expand Down
18 changes: 17 additions & 1 deletion integration-tests/tests/vm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use casper_engine_test_support::{
ExecuteRequestBuilder, InMemoryWasmTestBuilder, DEFAULT_ACCOUNT_ADDR,
DEFAULT_RUN_GENESIS_REQUEST,
};
use casper_event_standard::{Schemas, EVENTS_DICT, EVENTS_LENGTH, EVENTS_SCHEMA};
use casper_event_standard::{
Schemas, CES_VERSION, CES_VERSION_KEY, EVENTS_DICT, EVENTS_LENGTH, EVENTS_SCHEMA,
};
use casper_types::{
bytesrepr::{Bytes, FromBytes},
contracts::NamedKeys,
Expand Down Expand Up @@ -60,6 +62,18 @@ impl TestEnv {
.unwrap()
}

pub fn ces_version(&self) -> String {
let key = Key::from(*DEFAULT_ACCOUNT_ADDR);
self.context
.query(None, key, &[String::from(CES_VERSION_KEY)])
.unwrap()
.as_cl_value()
.unwrap()
.clone()
.into_t()
.unwrap()
}

pub fn event_at<T: FromBytes>(&self, index: u32) -> Option<T> {
let dictionary_seed_uref: URef = *self
.named_keys()
Expand Down Expand Up @@ -100,7 +114,9 @@ fn test_events_initalization() {
assert!(named_keys.contains_key(EVENTS_DICT));
assert!(named_keys.contains_key(EVENTS_LENGTH));
assert!(named_keys.contains_key(EVENTS_SCHEMA));
assert!(named_keys.contains_key(CES_VERSION_KEY));
assert_eq!(test_env.events_length(), 0);
assert_eq!(test_env.ces_version(), CES_VERSION);

let schemas = test_env.schemas();
let mut expected_schemas = Schemas::new();
Expand Down

0 comments on commit 4b42b52

Please sign in to comment.