1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original License18#![cfg_attr(not(feature = "std"), no_std)]1920use ink_lang as ink;2122#[ink::contract]23mod loadtester {24 use ink_storage::collections::Vec as InkVec;2526 #[ink(storage)]27 pub struct LoadTester {28 vector: InkVec<u64>,29 }3031 impl LoadTester {32 #[ink(constructor)]33 pub fn new() -> Self {34 Self {35 vector: InkVec::new(),36 }37 }3839 #[ink(message)]40 pub fn bloat(&mut self, count: u64){41 for i in 1..count+1 {42 self.vector.push(i);43 }44 }4546 #[ink(message)]47 pub fn get(&self) -> u128 {48 let mut sum: u128 = 0;49 for num in self.vector.iter() {50 sum += *num as u128;51 }52 sum53 }54 }5556 #[cfg(test)]57 mod tests {58 59 use super::*;6061 #[test]62 fn it_works() {63 let mut lt = LoadTester::new();64 lt.bloat(4);65 assert_eq!(lt.get(), [1,2,3,4]);66 lt.bloat(3);67 assert_eq!(lt.get(), [1,2,3,4,1,2,3]);68 }69 }70}difftreelog
source
tests/loadtester-src/lib.rs1.8 KiBsourcehistory