forked from near/nearcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yield/resume: init integration tests (near#10746)
This PR adds a couple of basic integration tests for yield execution: - tests behavior in the case `promise_yield_resume` is called with an unexpected data id - tests behavior in the case that `promise_yield_create` and `promise_yield_resume` are called within the same transaction Why do we start with these edge cases? As it stands the testing infrastructure in [runtime_user.rs](https://github.com/near/nearcore/blob/master/integration-tests/src/user/runtime_user.rs#L344) expects all receipts generated by a transaction to be resolved immediately once the transaction is executed. Calling yield without resume in any transaction breaks that assumption, so adding such tests will be a bit more involved. I had to drop the placeholder gas costs to get these tests to pass. I will follow up with a PR which tweaks RuntimeUser and adds tests for the main cases: - yield in one transaction, followed by resume in a later one - yield without resume, leading to a timeout
- Loading branch information
1 parent
836dbb7
commit d9409a0
Showing
7 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
yield_resume: { old: false, new: true } | ||
# FIXME(yield_resume): These fees are placeholders. | ||
wasm_yield_create_base: { old: 300_000_000_000_000, new: 50_000_000_000_000 } | ||
wasm_yield_create_base: { old: 300_000_000_000_000, new: 10_000_000_000_000 } | ||
wasm_yield_create_byte: { old: 300_000_000_000_000, new: 10_000_000 } | ||
wasm_yield_resume_base: { old: 300_000_000_000_000, new: 50_000_000_000_000 } | ||
wasm_yield_resume_base: { old: 300_000_000_000_000, new: 10_000_000_000_000 } | ||
wasm_yield_resume_byte: { old: 300_000_000_000_000, new: 100_000_000 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use crate::node::{Node, RuntimeNode}; | ||
use near_primitives::views::FinalExecutionStatus; | ||
|
||
/// Initial balance used in tests. | ||
pub const TESTING_INIT_BALANCE: u128 = 1_000_000_000 * NEAR_BASE; | ||
|
||
/// One NEAR, divisible by 10^24. | ||
pub const NEAR_BASE: u128 = 1_000_000_000_000_000_000_000_000; | ||
|
||
/// Max prepaid amount of gas. | ||
const MAX_GAS: u64 = 300_000_000_000_000; | ||
|
||
fn setup_test_contract(wasm_binary: &[u8]) -> RuntimeNode { | ||
let node = RuntimeNode::new(&"alice.near".parse().unwrap()); | ||
let account_id = node.account_id().unwrap(); | ||
let node_user = node.user(); | ||
let transaction_result = node_user | ||
.create_account( | ||
account_id, | ||
"test_contract".parse().unwrap(), | ||
node.signer().public_key(), | ||
TESTING_INIT_BALANCE / 2, | ||
) | ||
.unwrap(); | ||
assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); | ||
assert_eq!(transaction_result.receipts_outcome.len(), 2); | ||
|
||
let transaction_result = | ||
node_user.deploy_contract("test_contract".parse().unwrap(), wasm_binary.to_vec()).unwrap(); | ||
assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); | ||
assert_eq!(transaction_result.receipts_outcome.len(), 1); | ||
|
||
node | ||
} | ||
|
||
#[test] | ||
fn create_and_resume_in_one_call() { | ||
let node = setup_test_contract(near_test_contracts::nightly_rs_contract()); | ||
|
||
let yield_payload = vec![23u8; 16]; | ||
|
||
let res = node | ||
.user() | ||
.function_call( | ||
"alice.near".parse().unwrap(), | ||
"test_contract".parse().unwrap(), | ||
"call_yield_create_and_resume", | ||
yield_payload, | ||
MAX_GAS, | ||
0, | ||
) | ||
.unwrap(); | ||
|
||
// the yield callback is expected to execute successfully, | ||
// returning twice the value of the first byte of the payload | ||
assert_eq!( | ||
res.status, | ||
FinalExecutionStatus::SuccessValue(vec![46u8]), | ||
"{res:?} unexpected result; expected 46", | ||
); | ||
} | ||
|
||
#[test] | ||
fn resume_without_yield() { | ||
let node = setup_test_contract(near_test_contracts::nightly_rs_contract()); | ||
|
||
// payload followed by data id | ||
let args: Vec<u8> = vec![42u8; 12].into_iter().chain(vec![23u8; 32].into_iter()).collect(); | ||
|
||
let res = node | ||
.user() | ||
.function_call( | ||
"alice.near".parse().unwrap(), | ||
"test_contract".parse().unwrap(), | ||
"call_yield_resume", | ||
args, | ||
MAX_GAS, | ||
0, | ||
) | ||
.unwrap(); | ||
|
||
// expect the execution to suceed, but return 'false' | ||
assert_eq!( | ||
res.status, | ||
FinalExecutionStatus::SuccessValue(vec![0u8]), | ||
"{res:?} unexpected result; expected 0", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters