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#![cfg_attr(not(feature = "std"), no_std)]1819use ink_lang as ink;2021#[ink::contract]22mod loadtester {23 use ink_storage::collections::Vec as InkVec;2425 #[ink(storage)]26 pub struct LoadTester {27 vector: InkVec<u64>,28 }2930 impl LoadTester {31 #[ink(constructor)]32 pub fn new() -> Self {33 Self {34 vector: InkVec::new(),35 }36 }3738 #[ink(message)]39 pub fn bloat(&mut self, count: u64){40 for i in 1..count+1 {41 self.vector.push(i);42 }43 }4445 #[ink(message)]46 pub fn get(&self) -> u128 {47 let mut sum: u128 = 0;48 for num in self.vector.iter() {49 sum += *num as u128;50 }51 sum52 }53 }5455 #[cfg(test)]56 mod tests {57 58 use super::*;5960 #[test]61 fn it_works() {62 let mut lt = LoadTester::new();63 lt.bloat(4);64 assert_eq!(lt.get(), [1,2,3,4]);65 lt.bloat(3);66 assert_eq!(lt.get(), [1,2,3,4,1,2,3]);67 }68 }69}difftreelog
source
tests/loadtester-src/lib.rs1.8 KiBsourcehistory