Skip to content

Latest commit

 

History

History
97 lines (75 loc) · 2.67 KB

File metadata and controls

97 lines (75 loc) · 2.67 KB

Contract Syntax Error Fixes Summary

Issues Fixed

The grainlify-core contract in contracts/grainlify-core/src/lib.rs had malformed type definitions that prevented compilation. The following issues were resolved:

1. Line 14 - Constant Definition

Before:

const VERSION: u3env.storage().instance().get(&DataKey::Version).unwrap_or(0) = 1;

After:

const VERSION: u32 = 1;

2. Line 26 - Parameter Type in upgrade function

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>) {

3. Line 33 - Return Type in get_version function

Before:

pub fn get_version(env: Env) -> u3env.storage().instance().get(&DataKey::Version).unwrap_or(0) {

After:

pub fn get_version(env: Env) -> u32 {

4. Line 40 - Parameter Type in set_version function

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) {

Additional Changes Made

Added Comprehensive Tests

Added a test module with the following tests:

  • test_init_and_get_version() - Verifies initialization and version retrieval
  • test_set_version() - Tests setting a new version number
  • test_double_init_should_panic() - Ensures contract can't be initialized twice

How to Verify Compilation

To verify the contract compiles successfully:

  1. 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
  2. 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
  3. Navigate to the contract directory and build:

    cd contracts/grainlify-core
    cargo build
  4. Run the tests:

    cargo test

Verification Results

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.