near / near-sdk-rs

Rust library for writing NEAR smart contracts
https://near-sdk.io
Apache License 2.0
450 stars 242 forks source link

near sdk 5.1.0 tests issue #1168

Closed zavodil closed 3 weeks ago

zavodil commented 4 months ago

I can't run simple tests after upgrading to 5.1.0

#[cfg(test)]
mod tests {
    use crate::Contract;
    #[test]
    fn test_fees() {
      Contract::run(...)
   }
}

throws an error: error: linking with `cc` failed: exit status: 1 both for aarch64-apple-darwin and x86_64-apple-darwin

Switching to sdk 4.1.1 resolves the issue.

Full output:

error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="..." VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/var/folders/dr/_8d6dkm136j9fppw1cbck3k80000gp/T/rustcJqrqOl/symbols.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.121tfn9rdgmrk9zb.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.174qeo9hr85klszp.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.17odojlf8om3j2cg.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.18nthahdnah2060r.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.19aw5x26ogcv0kxo.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1bynck37a3ij4va8.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1ck531shgkxpn7bq.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1dtx0nb3sim0qsl.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1fh4ye5hol1u6uhs.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1gbvw4dy4w3alhin.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1hf7u3dgnvw3sdlq.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1hmn14bg44dis3a6.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1j71dg93a268vh1y.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1j9ouvxlavfb4ghi.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1mixm0purn1vgh0z.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1tmnym0naiuymbv2.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1vhx05w9ztf4ynmy.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.1xcv7y8u5flge8nq.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.21vs81i3z6coshc.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.23lg2a3vo32g4syd.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.24tswg2jr0wp94ht.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.27g0n2ex9kws72ln.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.282yphs8ymrf2qy2.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2aam9nfu00yh5hya.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2cjh9fvrp9uivkpf.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2csqoi5sssmo2ptr.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2efx1a1nd0fmu36f.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2jrn0h9uujo5xgdk.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2jvx4cm6n6q8pufy.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2nmu1fikrc0dm7l2.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2oz2fq05yei68sue.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2p0jp3pg51ctpk68.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.2xkkx3sun0lpmgua.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.36l11dl8qpwjdwc3.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3jn6h8cgi39xmuap.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3nw96jyviiuq58sd.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3qwnbi6uja9ilglc.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3rf7ssrj4p0e78eu.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3sn0j85wsujudc4u.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3xk42g7fjvg38yu9.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.43br6cx9ycwrr9nm.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.47oi74tfukyw0l1q.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4d7iad1tqjw9o97g.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4emsvm0x30s0l4xg.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4fq8gxr6ezxqt1s0.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4g21jfvfyw4jmwez.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4mkd2ixlgro0qd8m.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4rianp5b2z2alu62.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4s79br5ngradgpc2.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4us74iln10t7zjz7.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4x6a2nxpymp4qn1c.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4xq2ew7aa55xftjw.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.4y2osbbax8p3klu5.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.51r6hgz57q4tywr8.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.5420ctr1djudrwei.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.54h857fnmuyfjr6u.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.56zkofe67x44vk4l.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.5bf6f8f617dtul1s.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.5fmatpx31kyhc0yp.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.8mj4a7yzwyzcg0q.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.fpna8l8jw6hjruq.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.gbhm56vbm4a91ey.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.grdbfoxvce7akor.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.hcqhstopf8ccvwe.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.hu4tpi52gl78oub.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.j22d10lhqidxne1.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.jsb9pdm2nszdamx.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.pd1xz9hia98s2f4.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.szatj2hm0hv9g3f.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.tgdkb7kw8tgar5i.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.tjm0sd7wgmt0vaw.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.trg8yo3l5bo8lve.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.tzqmod6xcvktbqi.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.v2ryw7731805lkk.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.w0hneptamv9w8j0.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.wo3glfl1xz5vyz9.rcgu.o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88.3gfekq3ws4ujer3w.rcgu.o" "-L" "/Users/alice/projects/project/target/debug/deps" "-L" "/Users/alice/projects/project/target/debug/build/zstd-sys-47e9567e50994161/out" "-L" "/Users/alice/projects/project/target/debug/build/secp256k1-sys-5e9ccfa353c5761f/out" "-L" "/Users/alice/projects/project/target/debug/build/ring-4d90439a39140d9a/out" "-L" "/Users/alice/projects/project/target/debug/build/bzip2-sys-2a36b98c9aef8573/out/lib" "-L" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libtest-84815b13395e84a9.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgetopts-7ac2e74b655d6c3b.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunicode_width-9eac7050697471dc.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_std-8eaf56dcaf752a1d.rlib" "/Users/alice/projects/project/target/debug/deps/libuint-790a41a3b1ae3bc2.rlib" "/Users/alice/projects/project/target/debug/deps/libcrunchy-e94e673df0435356.rlib" "/Users/alice/projects/project/target/debug/deps/libstatic_assertions-ed684284fa28ef43.rlib" "/Users/alice/projects/project/target/debug/deps/libhex-f634932b7580e980.rlib" "/Users/alice/projects/project/target/debug/deps/libbyteorder-05ebb379751b905a.rlib" "/Users/alice/projects/project/target/debug/deps/libnear_contract_standards-d27279226c988768.rlib" "/Users/alice/projects/project/target/debug/deps/libnear_sdk-81c7d7b6f2128dd5.rlib" "/Users/alice/projects/project/target/debug/deps/libnear_token-b1245646e98f355f.rlib" "/Users/alice/projects/project/target/debug/deps/libnear_gas-4f42510a9b712fcf.rlib" "/Users/alice/projects/project/target/debug/deps/libschemars-480716a2a9c2bac3.rlib" "/Users/alice/projects/project/target/debug/deps/libdyn_clone-0eba758b5567553f.rlib" "/Users/alice/projects/project/target/debug/deps/libserde_json-093c652130275452.rlib" "/Users/alice/projects/project/target/debug/deps/libitoa-abea12239c1d93a5.rlib" "/Users/alice/projects/project/target/debug/deps/libryu-349637b5bcdd180a.rlib" "/Users/alice/projects/project/target/debug/deps/libindexmap-a2e8bc092fde1a4e.rlib" "/Users/alice/projects/project/target/debug/deps/libequivalent-eb0b3f7b5b507052.rlib" "/Users/alice/projects/project/target/debug/deps/libhashbrown-cc9b0da4886ccd7e.rlib" "/Users/alice/projects/project/target/debug/deps/libnear_account_id-6232a4b49dbf7ecc.rlib" "/Users/alice/projects/project/target/debug/deps/libbase64-96eaf892f61955c5.rlib" "/Users/alice/projects/project/target/debug/deps/libserde-af768578f48e84e0.rlib" "/Users/alice/projects/project/target/debug/deps/libbs58-e41b6658f7f53d08.rlib" "/Users/alice/projects/project/target/debug/deps/libnear_sys-fd9302c33701e853.rlib" "/Users/alice/projects/project/target/debug/deps/libonce_cell-e394b697f1234d68.rlib" "/Users/alice/projects/project/target/debug/deps/libborsh-8ffe7be36ed7507e.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-b7bbc4a3799f91ec.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-9a832f29e113f2ac.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-187acb73fb221979.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f379d77720ea5d52.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-5f995b6402184362.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-6d4646231255d040.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ddf92ea3297b7931.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-4bd9fc9ff7289783.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-bbf01e0821f9af8a.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-df3ad4119d36f143.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-3839cef552c2783c.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-130a17e70576817a.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f7bc4dcd41ebfabc.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-3b8c9f0215d4bce7.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-8e6430dafe1e0d1f.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-9d92a40a452d227c.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-fb23eb00feddf1cb.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-c6577f5d4f5dcd9a.rlib" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-6d556b0e8bf6f23e.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/alice/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/alice/projects/project/target/debug/deps/project-dc59c47c8a472c88" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: Undefined symbols for architecture arm64:
            "_log_utf8", referenced from:
                near_sdk::environment::env::log_str::hd1703a9764119ad9 in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_panic_utf8", referenced from:
                near_sdk::environment::env::panic_str::h877ab1cc96dd0f82 in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_read_register", referenced from:
                near_sdk::environment::env::read_register::h641748a8800b6aa6 in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_register_len", referenced from:
                near_sdk::environment::env::register_len::h06d04833acefa96e in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_storage_has_key", referenced from:
                near_sdk::environment::env::storage_has_key::h46109b23b59a29a0 in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_storage_read", referenced from:
                near_sdk::environment::env::storage_read::h3821bca4425137da in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_storage_remove", referenced from:
                near_sdk::environment::env::storage_remove::hfc229ef660944940 in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
            "_storage_write", referenced from:
                near_sdk::environment::env::storage_write::hc0ef9356fc09552f in libnear_sdk-81c7d7b6f2128dd5.rlib[3](near_sdk-81c7d7b6f2128dd5.near_sdk.5048736dee3ff8be-cgu.0.rcgu.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
frol commented 2 months ago

@zavodil Can you provide a minimum reproducible example, please?

StarGachinum commented 2 months ago

Hi! I faced similar issue while trying to test near-sdk-rs examples, but interesting enough when I tried to replicate this issue in ordinary smart contract everything was ok. Here is the way to get error: linking with 'cc' failed: exit status: 1 Go to near-sdk-rs/examples/test-contract/src/lib.rs Add this to the code:

use near_sdk::PanicOnDefault;

#[derive(PanicOnDefault)]
pub struct JustStruct {}

and create a test in test module:

#[cfg(not(target_arch = "wasm32"))]
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    #[should_panic]
    fn test_panic() {
        JustStruct::default();
    }
}

Then cargo test

frol commented 3 weeks ago

@zavodil @StarGachinum I have finally identified the problem. You have to enable unit-testing feature for near-sdk in your dev-dependencies:

https://github.com/near/near-sdk-rs/blob/0f46b0d596bbd5173b2c698b1fd7d6f8a2fc9a11/examples/status-message/Cargo.toml#L13-L14

I will keep this issue open to invite contributors to add this section to all the examples in this repo and make sure we run all the tests as it seems that currently we don't run those tests in some examples. At least, the following examples are affected and running cargo test fails there:

g4titanx commented 3 weeks ago

hi @frol i would love to take up this issue

onlydustapp[bot] commented 3 weeks ago

Hi @g4titanx! Maintainers during the ODHack #6.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

lordshashank commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have contributed to rust projects like rust_codegen_gcc, reth, etc and have relevant experience to tackle this

How I plan on tackling this issue

As problem is found by @frol, I would enable unit-testing feature in examples to run tests successfully

TropicalDog17 commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi team, I'm a software engineer who knows Rust well and has helped with many Rust open source projects(ibc-rs, reth, foundry-rs). I've been watching this project and I'm interested in it.

How I plan on tackling this issue

I will do research and also use @frol's clue to fix the issue, to ensure the repository tests run as expected.

frol commented 3 weeks ago

Oh wow, there is a lot of interest. I will assign it to @lordshashank as we had a discussion about another issue and I shared this one instead

frol commented 3 weeks ago

@lordshashank Are you working on it? If you won't submit a PR today, I will unassign it to let other contributors to take it