Skip to content

Commit

Permalink
wip: test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexytsu committed Jul 14, 2022
1 parent f7efed9 commit 94efb15
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
32 changes: 32 additions & 0 deletions fil_token/tests/blockstore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::{cell::RefCell, collections::HashMap};

use anyhow::Result;
use cid::Cid;
use fvm_ipld_blockstore::Blockstore;

/// An in-memory blockstore impl taken from filecoin-project/ref-fvm
#[derive(Debug, Default, Clone)]
pub struct MemoryBlockstore {
blocks: RefCell<HashMap<Cid, Vec<u8>>>,
}

impl MemoryBlockstore {
pub fn new() -> Self {
Self::default()
}
}

impl Blockstore for MemoryBlockstore {
fn has(&self, k: &Cid) -> Result<bool> {
Ok(self.blocks.borrow().contains_key(k))
}

fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>> {
Ok(self.blocks.borrow().get(k).cloned())
}

fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()> {
self.blocks.borrow_mut().insert(*k, block.into());
Ok(())
}
}
11 changes: 11 additions & 0 deletions fil_token/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod blockstore;
mod runtime;
use blockstore::MemoryBlockstore;
use runtime::TestRuntime;

use fil_token::token::{Token, TokenHelper};

#[test]
fn it_mints() {
let token = TokenHelper::new(MemoryBlockstore::new(), TestRuntime::new(1));
}
22 changes: 22 additions & 0 deletions fil_token/tests/runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::intrinsics::const_allocate;

use fil_token::runtime::Runtime;
pub struct TestRuntime {
caller: u64,
}

impl TestRuntime {
pub fn new(caller: u64) -> Self {
Self { caller }
}
}

impl Runtime for TestRuntime {
fn caller(&self) -> u64 {
return self.caller;
}

fn resolve_address(&self, addr: &fvm_shared::address::Address) -> anyhow::Result<u64> {
Ok(addr.id().unwrap())
}
}

0 comments on commit 94efb15

Please sign in to comment.