The k + 1 Symmetric Test Pattern for Smart Contracts
Abstract
:1. Introduction
2. Symmetric Test Pattern
3. Exchange Energy Smart Contract Example
- TheSameCommunity—prosumers must belong to the same community;
- DifferentProsumers—energy exchange is possible between two different prosumers;
- PositiveValue—the quantity of transferred energy must be a positive value;
- SourceSurplusPositive—surplus energy in the source node is a positive value;
- TargetNeedPositive—the target node’s need for energy is a positive value;
- SourceSurplusEnergy—the quantity of energy to transfer must not exceed the source prosumer surplus of energy;
- TargetProductionPositive—the energy generation of the target node is a positive value;
- TargetBatteryPositive—the target node’s battery charge level is positive;
- TargetNeedForEnergy—the target need for energy must be greater than the sum of energy stored in batteries and actual generation.
Listing 1. The source code of the SourceSurplusEnergy verification rule. |
public class SourceSurplusEnergy implements VerificationRule { @Override public boolean runRule(@NotNull Transaction t){ if (t.getSourceSurplus() >= t.getQuantity()) { System.out.println(“SourceSurplusEnergy - PASS”); return true; } else { System.out.println(“SourceSurplusEnergy - FAIL”); return false; } } } |
Listing 2. The ExchangeEnergyContract class implementation in Java. |
public class ExchangeEnergyContract extends SmartContract { public ExchangeEnergyContract(){ rulesList = Arrays.asList(new TheSameCommunity(), new DifferentProsumers(), new PositiveValue(), new SourceSurplusEnergy(), new TargetNeedForEnergy()); } @Override public boolean checkSC(Transaction tr){ boolean correct = false; for (VerificationRule vR : rulesList) { correct = vR.runRule(tr); if (!correct) break; } return correct; } } |
4. Test Classes Design and Implementation
Listing 3. The Test5VRsExchangeEnergyContract source code. |
class Test5VRsExchangeEnergyContract { ExchangeEnergyContract sC = new ExchangeEnergyContract(); @Test void checkSCPositive() { System.out.println("---⎵checkSCPositive"); Transaction tr = new Transaction(100, 300, 400, 20, 10, 1001, 1002, 101, 101); assertTrue(sC.checkSC(tr)); } @Test void checkSCNegativeTargetNeedForEnergy() { System.out.println("---⎵checkSCInNegativeTargetNeedForEnergy"); Transaction tr = new Transaction(100, 300, 400, 20, 500, 1001, 1002, 101, 101); assertFalse(sC.checkSC(tr)); } @Test void checkSCNegativeSourceSurplusEnergy() { System.out.println("---⎵checkSCNegativeSourceSurplusEnergy"); Transaction tr = new Transaction(100, 10, 400, 20, 10, 1001, 1002, 101, 101); assertFalse(sC.checkSC(tr)); } @Test void checkSCNegativePositiveValue() { System.out.println("---⎵checkSCNegativePositiveValue"); Transaction tr = new Transaction(0, 300, 400, 20, 10, 1001, 1002, 101, 101); assertFalse(sC.checkSC(tr)); } @Test void checkSCNegativeDifferentProsumers() { System.out.println("---⎵checkSCNegativeDifferentProsumers"); Transaction tr = new Transaction(100, 300, 400, 20, 10, 1001, 1001, 101, 101); assertFalse(sC.checkSC(tr)); } @Test void checkSCNegativeTheSameCommunity() { System.out.println("---⎵checkSCNegativeTheSameCommunity"); Transaction tr = new Transaction(100, 300, 400, 20, 10, 1001, 1002, 101, 102); assertFalse(sC.checkSC(tr)); } } |
5. Conclusions
Funding
Conflicts of Interest
References
- ISO/IEC 25010:2011; Systems and Software Engineering—Systems and Software Quality Requirements and Evaluation (SQuaRE)—System and Software Quality Models. ISO: Geneva, Switzerland, March 2011; pp. 1–34. Available online: https://www.iso.org/standard/35733.html (accessed on 11 June 2022).
- Tran, H.K.V.; Unterkalmsteiner, M.; Börstler, J.; bin Ali, N. Assessing test artifact quality—A tertiary study. Inf. Softw. Technol. 2021, 139, 106620. [Google Scholar] [CrossRef]
- The Agile Manifesto.Principles behind the Agile Manifesto. Available online: agilemanifesto.org/principles.html (accessed on 11 June 2022).
- Humble, J.; Farley, D. Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation, 1st ed.; Addison-Wesley Professional: Crawfordsville, IN, USA, 2010. [Google Scholar]
- Donca, I.-C.; Stan, O.P.; Misaros, M.; Gota, D.; Miclea, L. Method for Continuous Integration and Deployment Using a Pipeline Generator for Agile Software Projects. Sensors 2022, 22, 4637. [Google Scholar] [CrossRef] [PubMed]
- Shahin, M.; Babar, M.A.; Zhu, L. Continuous Integration, Delivery and Deployment: A Systematic Review on Approaches, Tools, Challenges and Practices. IEEE Access 2017, 5, 3909–3943. [Google Scholar] [CrossRef]
- Wang, Y.; Mäntylä, M.V.; Liu, Z.; Markkula, J. Test automation maturity improves product quality—Quantitative study of open source projects using continuous integration. J. Syst. Softw. 2022, 188, 111259. [Google Scholar] [CrossRef]
- Khan, S.U.R.; Lee, S.P.; Javaid, N.; Abdul, W. A Systematic Review on Test Suite Reduction: Approaches, Experiment’s Quality Evaluation, and Guidelines. IEEE Access 2018, 6, 11816–11841. [Google Scholar] [CrossRef]
- Al-Sabbagh, K.W.; Staron, M.; Hebig, R. Improving test case selection by handling class and attribute noise. J. Syst. Softw. 2022, 183, 111093. [Google Scholar] [CrossRef]
- Prado Lima, J.A.; Vergilio, S.R. Test Case Prioritization in Continuous Integration environments: A systematic mapping study. Inf. Softw. Technol. 2020, 121, 106268. [Google Scholar] [CrossRef]
- Coviello, C.; Romano, S.; Scanniello, G.; Marchetto, A.; Corazza, A.; Antoniol, G. Adequate vs. inadequate test suite reduction approaches. Inf. Softw. Technol. 2020, 119, 106224. [Google Scholar] [CrossRef]
- Kiran, A.; Butt, W.H.; Anwar, M.W.; Azam, F.; Maqbool, B. A Comprehensive Investigation of Modern Test Suite Optimization Trends, Tools and Techniques. IEEE Access 2019, 7, 89093–89117. [Google Scholar] [CrossRef]
- Powell, R. The 2022 State of Software Delivery. Available online: https://circleci.com/resources/2022-state-of-software-delivery/ (accessed on 11 June 2022).
- Xu, X.; Weber, I.; Staples, M. Architecture for Blockchain Applications, 1st ed.; Springer: Cham, Switzerland, 2019; pp. 5–7. [Google Scholar] [CrossRef]
- Sánchez-Gómez, N.; Torres-Valderrama, J.; García-García, J.A.; Gutiérrez, J.J.; Escalona, M.J. Model-Based Software Design and Testing in Blockchain Smart Contracts: A Systematic Literature Review. IEEE Access 2020, 8, 164556–164569. [Google Scholar] [CrossRef]
- Tong, Y.; Tan, W.; Guo, J.; Shen, B.; Qin, P.; Zhuo, S. Smart Contract Generation Assisted by AI-Based Word Segmentation. Appl. Sci. 2022, 12, 4773. [Google Scholar] [CrossRef]
- Zhang, L.; Wang, J.; Wang, W.; Jin, Z.; Zhao, C.; Cai, Z.; Chen, H. A Novel Smart Contract Vulnerability Detection Method Based on Information Graph and Ensemble Learning. Sensors 2022, 22, 3581. [Google Scholar] [CrossRef] [PubMed]
- Zardari, S.; Alam, S.; Al Salem, H.A.; Al Reshan, M.S.; Shaikh, A.; Malik, A.F.K.; Masood ur Rehman, M.; Mouratidis, H. A Comprehensive Bibliometric Assessment on Software Testing (2016–2021). Electronics 2022, 11, 1984. [Google Scholar] [CrossRef]
- Kirli, D.; Couraud, B.; Robu, V.; Salgado-Bravo, M.; Norbu, S.; Andoni, M.; Antonopoulos, I.; Negrete-Pincetic, M.; Flynn, D.; Kiprakis, A. Smart contracts in energy systems: A systematic review of fundamental approaches and implementations. Renew. Sustain. Energy Rev. 2022, 158, 112013. [Google Scholar] [CrossRef]
- Yahaya, A.S.; Javaid, N.; Alzahrani, F.A.; Rehman, A.; Ullah, I.; Shahid, A.; Shafiq, M. Blockchain Based Sustainable Local Energy Trading Considering Home Energy Management and Demurrage Mechanism. Sustainability 2020, 12, 3385. [Google Scholar] [CrossRef]
- Górski, T. The 1+5 Architectural Views Model in Designing Blockchain and IT System Integration Solutions. Symmetry 2021, 13, 2000. [Google Scholar] [CrossRef]
- Górski, T. Reconfigurable Smart Contracts for Renewable Energy Exchange with Re-Use of Verification Rules. Appl. Sci. 2022, 12, 5339. [Google Scholar] [CrossRef]
- The STP Repository. Available online: https://github.com/drGorski/SymmetricTestPattern (accessed on 1 June 2022).
No. | Test Result | VR1 | VR2 | VR3 | VR4 | VR5 |
---|---|---|---|---|---|---|
1 | PASS | 1 | 1 | 1 | 1 | 1 |
2 | FAIL | 1 | 1 | 1 | 1 | 0 |
3 | FAIL | 1 | 1 | 1 | 0 | 1 |
4 | FAIL | 1 | 1 | 0 | 1 | 1 |
5 | FAIL | 1 | 0 | 1 | 1 | 1 |
6 | FAIL | 0 | 1 | 1 | 1 | 1 |
No. | Test Result | VR1 | VR2 | VR3 | VR4 | VR5 |
---|---|---|---|---|---|---|
1 | PASS | 1 | 1 | 1 | 1 | 1 |
2 | FAIL | 1 | 1 | 1 | 1 | 0 |
3 | FAIL | 1 | 1 | 1 | 0 | 1 |
4 | FAIL | 1 | 1 | 1 | 0 | 0 |
5 | FAIL | 1 | 1 | 0 | 1 | 1 |
6 | FAIL | 1 | 1 | 0 | 1 | 0 |
7 | FAIL | 1 | 1 | 0 | 0 | 1 |
8 | FAIL | 1 | 1 | 0 | 0 | 0 |
9 | FAIL | 1 | 0 | 1 | 1 | 1 |
10 | FAIL | 1 | 0 | 1 | 1 | 0 |
11 | FAIL | 1 | 0 | 1 | 0 | 1 |
12 | FAIL | 1 | 0 | 1 | 0 | 0 |
13 | FAIL | 1 | 0 | 0 | 1 | 1 |
14 | FAIL | 1 | 0 | 0 | 1 | 0 |
15 | FAIL | 1 | 0 | 0 | 0 | 1 |
16 | FAIL | 1 | 0 | 0 | 0 | 0 |
17 | FAIL | 0 | 1 | 1 | 1 | 1 |
18 | FAIL | 0 | 1 | 1 | 1 | 0 |
19 | FAIL | 0 | 1 | 1 | 0 | 1 |
20 | FAIL | 0 | 1 | 1 | 0 | 0 |
21 | FAIL | 0 | 1 | 0 | 1 | 1 |
22 | FAIL | 0 | 1 | 0 | 1 | 0 |
23 | FAIL | 0 | 1 | 0 | 0 | 1 |
24 | FAIL | 0 | 1 | 0 | 0 | 0 |
25 | FAIL | 0 | 0 | 1 | 1 | 1 |
26 | FAIL | 0 | 0 | 1 | 1 | 0 |
27 | FAIL | 0 | 0 | 1 | 0 | 1 |
28 | FAIL | 0 | 0 | 1 | 0 | 0 |
29 | FAIL | 0 | 0 | 0 | 1 | 1 |
30 | FAIL | 0 | 0 | 0 | 1 | 0 |
31 | FAIL | 0 | 0 | 0 | 0 | 1 |
32 | FAIL | 0 | 0 | 0 | 0 | 0 |
No. of VRs | No. of Test Cases (Full Coverage) | No. of Test Cases (STP) | No. of Reduced Test Cases | |
---|---|---|---|---|
1 | 2 | 2 | 0 | 0.00% |
2 | 4 | 3 | 1 | 25.00% |
3 | 8 | 4 | 4 | 50.00% |
4 | 16 | 5 | 11 | 68.75% |
5 | 32 | 6 | 26 | 81.25% |
6 | 64 | 7 | 57 | 89.06% |
7 | 128 | 8 | 120 | 93.75% |
8 | 256 | 9 | 247 | 96.48% |
9 | 512 | 10 | 502 | 98.05% |
10 | 1024 | 11 | 1013 | 98.93% |
11 | 2048 | 12 | 2036 | 99.41% |
12 | 4096 | 13 | 4083 | 99.68% |
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |
© 2022 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Górski, T. The k + 1 Symmetric Test Pattern for Smart Contracts. Symmetry 2022, 14, 1686. https://doi.org/10.3390/sym14081686
Górski T. The k + 1 Symmetric Test Pattern for Smart Contracts. Symmetry. 2022; 14(8):1686. https://doi.org/10.3390/sym14081686
Chicago/Turabian StyleGórski, Tomasz. 2022. "The k + 1 Symmetric Test Pattern for Smart Contracts" Symmetry 14, no. 8: 1686. https://doi.org/10.3390/sym14081686
APA StyleGórski, T. (2022). The k + 1 Symmetric Test Pattern for Smart Contracts. Symmetry, 14(8), 1686. https://doi.org/10.3390/sym14081686