Skip to content

Commit 09c57a1

Browse files
author
Yucong Sun
authored
Creating the first unittest for AccountResource (#6)
1 parent 4824e9d commit 09c57a1

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -euo pipefail
33

44
# Build libra-dev first
55
cd libra-dev
6+
cargo test
67
cargo build
78
cd ..
89

libra-dev/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libra-dev/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ edition = "2018"
1010
libra-types = { git = "https://github.com/libra/libra.git", branch = "testnet" }
1111
libra-crypto = { git = "https://github.com/libra/libra.git", branch = "testnet" }
1212

13+
[dev-dependencies]
14+
lcs = { git = "https://github.com/libra/libra.git", branch = "testnet", package = "libra-canonical-serialization" }
15+
1316
[lib]
1417
crate-type = ["staticlib"]

libra-dev/src/account_resource.rs

+31
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,34 @@ pub unsafe extern "C" fn account_resource_from_lcs(
117117
received_events,
118118
};
119119
}
120+
121+
/// Generate an AccountBlob and verify we can parse it
122+
#[test]
123+
fn test_get_account_resource() {
124+
use std::{collections::BTreeMap, convert::TryInto};
125+
use libra_types::account_config::account_resource_path;
126+
use libra_types::account_config::AccountResource;
127+
128+
// Figure out how to use Libra code to generate AccountStateBlob directly, not involving btreemap directly
129+
let mut map: BTreeMap<Vec<u8>, Vec<u8>> = BTreeMap::new();
130+
let ar = AccountResource::new(
131+
987654321,
132+
123456789,
133+
ByteArray::new(vec![1,2,3,4]),
134+
true,
135+
false,
136+
EventHandle::default(),
137+
EventHandle::default(),
138+
);
139+
// Fill in data
140+
map.insert(account_resource_path(), lcs::to_bytes(&ar ).expect("Must success"));
141+
142+
let account_state_blob = lcs::to_bytes(&map).expect("LCS serialization failed");
143+
144+
let result = unsafe {
145+
account_resource_from_lcs(account_state_blob.as_ptr(), account_state_blob.len())
146+
};
147+
148+
assert_eq!(result.balance, ar.balance());
149+
assert_eq!(result.sequence, ar.sequence_number());
150+
}

0 commit comments

Comments
 (0)