The grainlify-core contract in contracts/grainlify-core/src/lib.rs had malformed type definitions that prevented compilation. The following issues were resolved:
Before:
const VERSION: u3env.storage().instance().get(&DataKey::Version).unwrap_or(0) = 1;After:
const VERSION: u32 = 1;Before:
pub fn upgrade(env: Env, new_wasm_hash: BytesN<3env.storage().instance().get(&DataKey::Version).unwrap_or(0)>) {After:
pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>) {Before:
pub fn get_version(env: Env) -> u3env.storage().instance().get(&DataKey::Version).unwrap_or(0) {After:
pub fn get_version(env: Env) -> u32 {Before:
pub fn set_version(env: Env, new_version: u3env.storage().instance().get(&DataKey::Version).unwrap_or(0)) {After:
pub fn set_version(env: Env, new_version: u32) {Added a test module with the following tests:
test_init_and_get_version()- Verifies initialization and version retrievaltest_set_version()- Tests setting a new version numbertest_double_init_should_panic()- Ensures contract can't be initialized twice
To verify the contract compiles successfully:
-
Ensure Rust and Soroban are installed:
# Install Rust if not present curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install Soroban CLI cargo install --locked soroban-cli
-
For Windows users only: Install Visual Studio Build Tools
- Download and install "Build Tools for Visual Studio" from https://visualstudio.microsoft.com/downloads/
- Make sure to select the "C++ build tools" workload
- Or install Visual Studio Community with C++ development tools
- This is required because Rust on Windows uses the MSVC linker
-
Navigate to the contract directory and build:
cd contracts/grainlify-core cargo build -
Run the tests:
cargo test
The syntax errors have been fixed and the contract should now compile without errors. The tests cover the main functionality including:
- Contract initialization
- Version retrieval
- Version setting/updating
- Protection against double initialization
All functionality remains intact while fixing the malformed type definitions that were preventing compilation.