forked from diem/diem
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnatives.rs
110 lines (104 loc) · 4.03 KB
/
natives.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright © Diem Foundation
// Parts of the project are originally copyright © Meta Platforms, Inc.
// SPDX-License-Identifier: Apache-2.0
//////// 0L ////////
// expose out of "testing"
// #[cfg(feature = "testing")]
use diem_framework::natives::cryptography::algebra::AlgebraContext;
use diem_gas::{AbstractValueSizeGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION};
// #[cfg(feature = "testing")]
use diem_types::chain_id::ChainId;
use diem_types::{
account_config::CORE_CODE_ADDRESS,
on_chain_config::{Features, TimedFeatures},
};
use move_vm_runtime::native_functions::NativeFunctionTable;
use std::sync::Arc;
// #[cfg(feature = "testing")]
use {
diem_framework::natives::{
aggregator_natives::NativeAggregatorContext, code::NativeCodeContext,
cryptography::ristretto255_point::NativeRistrettoPointContext,
transaction_context::NativeTransactionContext,
},
move_vm_runtime::native_extensions::NativeContextExtensions,
move_vm_test_utils::BlankStorage,
once_cell::sync::Lazy,
};
// #[cfg(feature = "testing")]
static DUMMY_RESOLVER: Lazy<BlankStorage> = Lazy::new(|| BlankStorage);
pub fn diem_natives(
gas_params: NativeGasParameters,
abs_val_size_gas_params: AbstractValueSizeGasParameters,
gas_feature_version: u64,
timed_features: TimedFeatures,
features: Arc<Features>,
) -> NativeFunctionTable {
diem_move_stdlib::natives::all_natives(CORE_CODE_ADDRESS, gas_params.move_stdlib.clone())
.into_iter()
.filter(|(_, name, _, _)| name.as_str() != "vector")
.chain(diem_framework::natives::all_natives(
CORE_CODE_ADDRESS,
gas_params.move_stdlib,
gas_params.diem_framework,
timed_features,
features,
move |val| abs_val_size_gas_params.abstract_value_size(val, gas_feature_version),
))
.chain(move_table_extension::table_natives(
CORE_CODE_ADDRESS,
gas_params.table,
))
.collect()
}
pub fn assert_no_test_natives(err_msg: &str) {
assert!(
diem_natives(
NativeGasParameters::zeros(),
AbstractValueSizeGasParameters::zeros(),
LATEST_GAS_FEATURE_VERSION,
TimedFeatures::enable_all(),
Arc::new(Features::default())
)
.into_iter()
.all(|(_, module_name, func_name, _)| {
!(module_name.as_str() == "unit_test"
&& func_name.as_str() == "create_signers_for_testing"
|| module_name.as_str() == "ed25519"
&& func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "ed25519" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "multi_ed25519"
&& func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "multi_ed25519" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "bls12381"
&& func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "bls12381" && func_name.as_str() == "sign_internal"
|| module_name.as_str() == "bls12381"
&& func_name.as_str() == "generate_proof_of_possession_internal")
}),
"{}",
err_msg
)
}
//////// 0L ////////
// This may not need to be only a feature="testing"
// #[cfg(feature = "testing")]
pub fn configure_for_unit_test() {
move_unit_test::extensions::set_extension_hook(Box::new(unit_test_extensions_hook))
}
// #[cfg(feature = "testing")]
fn unit_test_extensions_hook(exts: &mut NativeContextExtensions) {
exts.add(NativeCodeContext::default());
exts.add(NativeTransactionContext::new(
vec![1],
vec![1],
ChainId::test().id(),
)); // We use the testing environment chain ID here
exts.add(NativeAggregatorContext::new(
[0; 32],
&*DUMMY_RESOLVER,
true,
));
exts.add(NativeRistrettoPointContext::new());
exts.add(AlgebraContext::new());
}