12 releases (7 stable)

1.5.1 Feb 28, 2025
1.4.0 Oct 18, 2024
1.2.0 Jul 30, 2024
0.9.1 Apr 15, 2024
0.8.1 Mar 1, 2024

#4 in #odra

Download history 43/week @ 2024-12-08 1/week @ 2024-12-15 121/week @ 2025-01-05 11/week @ 2025-01-12 32/week @ 2025-02-09 6/week @ 2025-02-16 112/week @ 2025-02-23 39/week @ 2025-03-02 2/week @ 2025-03-09 3/week @ 2025-03-16

74 downloads per month
Used in odra-modules

MIT license

255KB
5K SLoC

This crate provides a testing environment for the Odra VM.

It is meant to be used in the unit tests of the Odra contracts.

Example

#[test]
fn test() {
   let env = odra_test::env();
   let caller = env.get_account(0);

   // Test your contract here.
}

Odra - Smart contracts for Casper Network.

Docs | Installation | Tutorials | Cargo Odra | Discord | Blog

GitHub Workflow Status Code coverage Version License Language

Table of Contents

Usage

Use Cargo Odra to generate, build and test you code.

Example

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.

Tests

Before running tests make sure you have following packages installed:

Run tests:

$ just test

Contact

Need some help? Write to contract@odra.dev.

Dependencies

~21–34MB
~586K SLoC