Skip to content

Commit

Permalink
Merge branch 'master' into feat/payout
Browse files Browse the repository at this point in the history
  • Loading branch information
frol committed Sep 12, 2023
2 parents 8e5e777 + db29912 commit 14ac453
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 91 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"near-sdk",
"near-sdk-macros",
Expand Down
19 changes: 2 additions & 17 deletions near-sdk-macros/src/core_impl/info_extractor/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,8 @@ impl Visitor {
}

pub fn visit_private_attr(&mut self, _attr: &Attribute) -> syn::Result<()> {
use VisitorKind::*;

match self.kind {
Call | View => {
self.parsed_data.is_private = true;
Ok(())
}
Init => {
// TODO: return an error instead in 5.0
// see https://github.com/near/near-sdk-rs/issues/1040
println!("near_bindgen: private init functions will be disallowed in 5.0");
Ok(())

// let message = format!("{} function can't be private.", self.kind);
// Err(Error::new(attr.span(), message))
}
}
self.parsed_data.is_private = true;
Ok(())
}

pub fn visit_result_serializer_attr(
Expand Down
7 changes: 6 additions & 1 deletion near-sdk/compilation_tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ fn compilation_tests() {
t.pass("compilation_tests/function_error.rs");
t.pass("compilation_tests/enum_near_bindgen.rs");
t.pass("compilation_tests/schema_derive.rs");
t.compile_fail("compilation_tests/schema_derive_invalids.rs");
if rustversion::cfg!(since(1.72)) {
// The compilation error output has slightly changed in 1.72, so we
// snapshoted this new version
t.compile_fail("compilation_tests/schema_derive_invalids.rs");
}
t.compile_fail("compilation_tests/generic_function.rs");
t.compile_fail("compilation_tests/generic_const_function.rs");
t.pass("compilation_tests/self_support.rs");
Expand All @@ -30,4 +34,5 @@ fn compilation_tests() {
//
// t.compile_fail("compilation_tests/self_forbidden_in_non_init_fn_return.rs");
// t.compile_fail("compilation_tests/self_forbidden_in_non_init_fn_arg.rs");
t.pass("compilation_tests/private_init_method.rs");
}
22 changes: 22 additions & 0 deletions near-sdk/compilation_tests/private_init_method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Even though it might feel unintuitive, a method can be both private and init.
//! See: https://github.com/near/near-sdk-rs/issues/1040#issuecomment-1687126452

use borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::near_bindgen;

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
struct Incrementer {
value: u32,
}

#[near_bindgen]
impl Incrementer {
#[private]
#[init]
pub fn new(starting_value: u32) -> Self {
Self { value: starting_value }
}
}

fn main() {}
38 changes: 19 additions & 19 deletions near-sdk/compilation_tests/schema_derive_invalids.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ error: `NearSchema` does not support derive for unions
| |_^

error[E0277]: the trait bound `Inner: JsonSchema` is not satisfied
--> compilation_tests/schema_derive_invalids.rs:6:14
|
6 | struct Outer(Inner);
| ^^^^^ the trait `JsonSchema` is not implemented for `Inner`
|
= help: the following other types implement trait `JsonSchema`:
&'a T
&'a mut T
()
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
(T0, T1, T2, T3, T4, T5)
and 165 others
--> compilation_tests/schema_derive_invalids.rs:6:14
|
6 | struct Outer(Inner);
| ^^^^^ the trait `JsonSchema` is not implemented for `Inner`
|
= help: the following other types implement trait `JsonSchema`:
bool
char
isize
i8
i16
i32
i64
i128
and $N others
note: required by a bound in `SchemaGenerator::subschema_for`
--> $CARGO/schemars-0.8.12/src/gen.rs
|
| pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
| ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`
--> $CARGO/schemars-0.8.13/src/gen.rs
|
| pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
| ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`
53 changes: 26 additions & 27 deletions near-sdk/src/collections/tree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ mod tests {
#[test]
fn test_lower() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());
let vec: Vec<u32> = vec![10, 20, 30, 40, 50];
let vec = [10, 20, 30, 40, 50];

for x in vec.iter() {
map.insert(x, &1);
Expand All @@ -1154,7 +1154,7 @@ mod tests {
#[test]
fn test_higher() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());
let vec: Vec<u32> = vec![10, 20, 30, 40, 50];
let vec = [10, 20, 30, 40, 50];

for x in vec.iter() {
map.insert(x, &1);
Expand All @@ -1174,7 +1174,7 @@ mod tests {
#[test]
fn test_floor_key() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());
let vec: Vec<u32> = vec![10, 20, 30, 40, 50];
let vec = [10, 20, 30, 40, 50];

for x in vec.iter() {
map.insert(x, &1);
Expand All @@ -1194,7 +1194,7 @@ mod tests {
#[test]
fn test_ceil_key() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());
let vec: Vec<u32> = vec![10, 20, 30, 40, 50];
let vec = [10, 20, 30, 40, 50];

for x in vec.iter() {
map.insert(x, &1);
Expand Down Expand Up @@ -1231,7 +1231,7 @@ mod tests {

#[test]
fn test_remove_3_desc() {
let vec: Vec<u32> = vec![3, 2, 1];
let vec = [3, 2, 1];
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

for x in &vec {
Expand All @@ -1250,7 +1250,7 @@ mod tests {

#[test]
fn test_remove_3_asc() {
let vec: Vec<u32> = vec![1, 2, 3];
let vec = [1, 2, 3];
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

for x in &vec {
Expand All @@ -1269,8 +1269,8 @@ mod tests {

#[test]
fn test_remove_7_regression_1() {
let vec: Vec<u32> =
vec![2104297040, 552624607, 4269683389, 3382615941, 155419892, 4102023417, 1795725075];
let vec =
[2104297040, 552624607, 4269683389, 3382615941, 155419892, 4102023417, 1795725075];
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

for x in &vec {
Expand All @@ -1289,8 +1289,7 @@ mod tests {

#[test]
fn test_remove_7_regression_2() {
let vec: Vec<u32> =
vec![700623085, 87488544, 1500140781, 1111706290, 3187278102, 4042663151, 3731533080];
let vec = [700623085, 87488544, 1500140781, 1111706290, 3187278102, 4042663151, 3731533080];
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

for x in &vec {
Expand All @@ -1309,7 +1308,7 @@ mod tests {

#[test]
fn test_remove_9_regression() {
let vec: Vec<u32> = vec![
let vec = [
1186903464, 506371929, 1738679820, 1883936615, 1815331350, 1512669683, 3581743264,
1396738166, 1902061760,
];
Expand All @@ -1331,7 +1330,7 @@ mod tests {

#[test]
fn test_remove_20_regression_1() {
let vec: Vec<u32> = vec![
let vec = [
552517392, 3638992158, 1015727752, 2500937532, 638716734, 586360620, 2476692174,
1425948996, 3608478547, 757735878, 2709959928, 2092169539, 3620770200, 783020918,
1986928932, 200210441, 1972255302, 533239929, 497054557, 2137924638,
Expand All @@ -1354,7 +1353,7 @@ mod tests {

#[test]
fn test_remove_7_regression() {
let vec: Vec<u32> = vec![280, 606, 163, 857, 436, 508, 44, 801];
let vec = [280, 606, 163, 857, 436, 508, 44, 801];

let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

Expand All @@ -1377,8 +1376,8 @@ mod tests {

#[test]
fn test_insert_8_remove_4_regression() {
let insert = vec![882, 398, 161, 76];
let remove = vec![242, 687, 860, 811];
let insert = [882, 398, 161, 76];
let remove = [242, 687, 860, 811];

let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

Expand Down Expand Up @@ -1443,8 +1442,8 @@ mod tests {

#[test]
fn test_insert_2_remove_2_regression() {
let ins: Vec<u32> = vec![11760225, 611327897];
let rem: Vec<u32> = vec![2982517385, 1833990072];
let ins = [11760225, 611327897];
let rem = [2982517385, 1833990072];

let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());
map.insert(&ins[0], &1);
Expand Down Expand Up @@ -1581,8 +1580,8 @@ mod tests {
fn test_iter_from() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

let one: Vec<u32> = vec![10, 20, 30, 40, 50];
let two: Vec<u32> = vec![45, 35, 25, 15, 5];
let one = [10, 20, 30, 40, 50];
let two = [45, 35, 25, 15, 5];

for x in &one {
map.insert(x, &42);
Expand Down Expand Up @@ -1625,8 +1624,8 @@ mod tests {
fn test_iter_rev_from() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

let one: Vec<u32> = vec![10, 20, 30, 40, 50];
let two: Vec<u32> = vec![45, 35, 25, 15, 5];
let one = [10, 20, 30, 40, 50];
let two = [45, 35, 25, 15, 5];

for x in &one {
map.insert(x, &42);
Expand Down Expand Up @@ -1663,8 +1662,8 @@ mod tests {
fn test_range() {
let mut map: TreeMap<u32, u32> = TreeMap::new(next_trie_id());

let one: Vec<u32> = vec![10, 20, 30, 40, 50];
let two: Vec<u32> = vec![45, 35, 25, 15, 5];
let one = [10, 20, 30, 40, 50];
let two = [45, 35, 25, 15, 5];

for x in &one {
map.insert(x, &42);
Expand Down Expand Up @@ -1760,17 +1759,17 @@ mod tests {

#[test]
fn test_balance_regression_1() {
let insert = vec![(2, 0), (3, 0), (4, 0)];
let remove = vec![0, 0, 0, 1];
let insert = [(2, 0), (3, 0), (4, 0)];
let remove = [0, 0, 0, 1];

let map = avl(&insert, &remove);
assert!(is_balanced(&map, map.root));
}

#[test]
fn test_balance_regression_2() {
let insert = vec![(1, 0), (2, 0), (0, 0), (3, 0), (5, 0), (6, 0)];
let remove = vec![0, 0, 0, 3, 5, 6, 7, 4];
let insert = [(1, 0), (2, 0), (0, 0), (3, 0), (5, 0), (6, 0)];
let remove = [0, 0, 0, 3, 5, 6, 7, 4];

let map = avl(&insert, &remove);
assert!(is_balanced(&map, map.root));
Expand Down
Loading

0 comments on commit 14ac453

Please sign in to comment.