Skip to content

Commit

Permalink
Delete expect warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasavola committed May 10, 2024
1 parent 611ffa4 commit afd390a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 30 deletions.
18 changes: 18 additions & 0 deletions test-cases/incorrect-exponentiation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[workspace]
exclude = [".cargo", "target"]
members = ["incorrect-exponentiation-*/*"]
resolver = "2"
[workspace.dependencies]
soroban-sdk = { version = "20.3.2" }
[profile.release]
codegen-units = 1
debug = 0
debug-assertions = false
lto = true
opt-level = "z"
overflow-checks = true
panic = "abort"
strip = "symbols"
[profile.release-with-logs]
debug-assertions = true
inherits = "release"
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
[package]
name = "incorrect-exponentiation-remediated-1"
version = "0.0.0"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
#![no_std]

use soroban_sdk::{contract, contractimpl, contracttype, Env};
use soroban_sdk::{contract, contractimpl,contracterror, contracttype, Env};

#[contracttype]
#[derive(Clone)]
enum DataKey {
Data,
}

// Agrega el atributo #[contracterror] a la definición de IEError
#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum IEError {
CouldntRetrieveData = 1,
}

#[contract]
pub struct IncorrectExponentiation;

#[contractimpl]
impl IncorrectExponentiation {

pub fn set_data(e: Env, new_data: u128) {
e.storage()
.instance()
.set::<DataKey, u128>(&DataKey::Data, &new_data);
}

pub fn exp_data_3(e: Env) -> u128 {
let data = e.storage()
.instance()
.get::<DataKey, u128>(&DataKey::Data)
.expect("Data not found");

data.pow(3)
pub fn exp_data_3(e: Env) -> Result<u128, IEError> {
let data:Option<u128> = e.storage().instance().get(&DataKey::Data);
match data
{
Some(x) => return Ok(x.pow(3)),
None =>return Err(IEError::CouldntRetrieveData),
}
}

}

#[cfg(test)]
Expand All @@ -47,10 +53,8 @@ mod tests {



client.set_data(&10_u128);
client.set_data(&3_u128);

assert_eq!(client.exp_data_3(), 1000);
assert_eq!(client.exp_data_3(), 27);
}
}


Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
#![no_std]

use soroban_sdk::{contract, contractimpl, contracttype, Env};
use soroban_sdk::{contract, contractimpl,contracterror, contracttype, Env};

#[contracttype]
#[derive(Clone)]
enum DataKey {
Data,
}

// Agrega el atributo #[contracterror] a la definición de IEError
#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum IEError {
CouldntRetrieveData = 1,
}

#[contract]
pub struct IncorrectExponentiation;

#[contractimpl]
impl IncorrectExponentiation {

pub fn set_data(e: Env, new_data: u128) {
e.storage()
.instance()
.set::<DataKey, u128>(&DataKey::Data, &new_data);
}


pub fn exp_data_3(e: Env) -> u128 {
let mut data = e.storage()
.instance()
.get::<DataKey, u128>(&DataKey::Data)
.expect("Data not found");

data ^= 3;
data
pub fn exp_data_3(e: Env) -> Result<u128, IEError> {
let data: Option<u128> = e.storage().instance().get(&DataKey::Data);
match data {
Some(mut x) => {
x ^= 3;
Ok(x)
},
None => Err(IEError::CouldntRetrieveData),
}
}

}
Expand Down

0 comments on commit afd390a

Please sign in to comment.