Crates.io | odra |
lib.rs | odra |
version | 1.4.0 |
source | src |
created_at | 2022-08-09 14:15:01.296195 |
updated_at | 2024-10-18 09:29:24.968458 |
description | Smart contracts for Casper Network. |
homepage | https://odra.dev/docs |
repository | https://github.com/odradev/odra |
max_upload_size | |
id | 641831 |
size | 7,071 |
Docs | Installation | Tutorials | Cargo Odra | Discord | Blog
Use Cargo Odra to generate, build and test you code.
use odra::prelude::*;
use odra::Var;
#[odra::module]
pub struct Flipper {
value: Var<bool>,
}
#[odra::module]
impl Flipper {
pub fn init(&mut self) {
self.value.set(false);
}
pub fn set(&mut self, value: bool) {
self.value.set(value);
}
pub fn flip(&mut self) {
self.value.set(!self.get());
}
pub fn get(&self) -> bool {
self.value.get_or_default()
}
}
#[cfg(test)]
mod tests {
use crate::flipper::FlipperHostRef;
use odra::host::{Deployer, NoArgs};
#[test]
fn flipping() {
let env = odra_test::env();
let mut contract = FlipperHostRef::deploy(&env, NoArgs);
assert!(!contract.get());
contract.flip();
assert!(contract.get());
}
}
Checkout our examples. It shows most of Odra features.
Before running tests make sure you have following packages installed:
wasm32-unknown-unknown
target.cargo-odra
(see Cargo Odra)just
(see just)Run tests:
$ just test
Need some help? Write to contract@odra.dev.