Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

ink_prelude::string::String problem #96

Open
xhuanlee opened this issue Feb 20, 2021 · 4 comments
Open

ink_prelude::string::String problem #96

xhuanlee opened this issue Feb 20, 2021 · 4 comments

Comments

@xhuanlee
Copy link

a2c8860eb830fae5b8a8609f62a9439

set value to hello, it returns u0014hello;

b3c0885fb73e8857682e6644d74b4d9

set value to hello, world!, it returns 4hello, world!

contract source

// Copyright 2018-2021 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]

use ink_lang as ink;

#[ink::contract]
pub mod flipper {

    use ink_prelude::string::String;
    
    #[ink(storage)]
    pub struct Flipper {
        value: String,
    }

    impl Flipper {
        /// Creates a new flipper smart contract initialized with the given value.
        #[ink(constructor)]
        pub fn new(init_value: String) -> Self {
            Self { value: init_value }
        }

        /// Creates a new flipper smart contract initialized to `false`.
        #[ink(constructor)]
        pub fn default() -> Self {
            Self::new(String::from("hello, world!"))
        }

        /// Flips the current value of the Flipper's bool.
        #[ink(message)]
        pub fn set(&mut self, v:String) {
            self.value = v;
        }

        /// Returns the current value of the Flipper's bool.
        #[ink(message)]
        pub fn get(&self) -> String {
            self.value.clone()
        }
    }

    #[cfg(test)]
    mod tests {
        use super::*;

        #[test]
        fn default_works() {
            let flipper = Flipper::default();
            assert_eq!(flipper.get(), String::from("hello, world!"));
        }

        #[test]
        fn it_works() {
            let mut flipper = Flipper::new(String::from("Good day"));
            assert_eq!(flipper.get(), String::from("Good day"));
            flipper.set(String::from("Good morning"));
            assert_eq!(flipper.get(), String::from("Good morning"));
        }
    }
}
@xhuanlee xhuanlee changed the title wrong String value ink_prelude::string::String problem Feb 20, 2021
@atenjin
Copy link

atenjin commented Feb 20, 2021

I have submmit this issue in https://github.com/polkadot-js/apps, I think this is a bug in apps.
more detils refer to this issue
polkadot-js#4621

@xhuanlee
Copy link
Author

I have submmit this issue in https://github.com/polkadot-js/apps, I think this is a bug in apps.
more detils refer to this issue
polkadot-js/apps#4621

I'll take a look at it, Thank you~

@cmichi cmichi transferred this issue from use-ink/ink Apr 15, 2021
@cmichi
Copy link

cmichi commented Apr 15, 2021

The issue can be reproduced with the Canvas UI. This is how it looks:

screenshot-paritytech github io-2021 04 15-20_13_47

�huhu
�lala

I've uploaded the .contract file for the contract posted by @xhuanlee here:
flipper.contract.zip.

@atenjin
Copy link

atenjin commented Apr 16, 2021

obviously this is a bug in apps, I have proved this by using europa, and I already summited the issue in apps polkadot-js#4621, waiting for jacob to fix it for a long time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants