From 9635dc594290318e06ad8d33c9770e74e494b4df Mon Sep 17 00:00:00 2001 From: Stefan Stefanov Date: Tue, 17 Oct 2023 13:39:07 +0300 Subject: [PATCH] Adding tests for scoping Signed-off-by: Stefan Stefanov --- contracts/solidity/scoping/Scoping.sol | 25 +++++++++++++ test/constants.js | 2 + test/solidity/defaults/defaults.js | 52 ++++++++++++++++++++++++++ test/solidity/scoping/scoping.js | 39 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 contracts/solidity/scoping/Scoping.sol create mode 100644 test/solidity/defaults/defaults.js create mode 100644 test/solidity/scoping/scoping.js diff --git a/contracts/solidity/scoping/Scoping.sol b/contracts/solidity/scoping/Scoping.sol new file mode 100644 index 000000000..519348a4d --- /dev/null +++ b/contracts/solidity/scoping/Scoping.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.20; + +contract Scoping { + function minimalScoping() pure public { + { + uint same; + same = 1; + } + + { + uint same; + same = 3; + } + } + + function reassign() pure public returns (uint) { + uint x = 1; + { + x = 2; // this will assign to the outer variable + uint x; + } + return x; // x has value 2 + } +} diff --git a/test/constants.js b/test/constants.js index c762ba216..b7d5c6703 100644 --- a/test/constants.js +++ b/test/constants.js @@ -111,6 +111,8 @@ const Contract = { Functions: 'Functions', FunctionsChild: 'FunctionsChild', FunctionsParent: 'FunctionsParent', + Defaults: 'Defaults', + Scoping: 'Scoping', } const CALL_EXCEPTION = 'CALL_EXCEPTION' diff --git a/test/solidity/defaults/defaults.js b/test/solidity/defaults/defaults.js new file mode 100644 index 000000000..709e03466 --- /dev/null +++ b/test/solidity/defaults/defaults.js @@ -0,0 +1,52 @@ +const { expect, assert } = require('chai') +const { ethers } = require('hardhat') +const Constants = require('../../constants') + +describe('Solidity Errors', function () { + let signers + let contract + + before(async function () { + signers = await ethers.getSigners() + + const factory = await ethers.getContractFactory(Constants.Contract.Errors) + contract = await factory.deploy() + }) + + it('should confirm solidity functionality: "uint" cover different variations', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "int" cover different variations', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "fixedx" cover different variations', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "unfixedx" cover different variations', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "bytes"', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: string', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "[]"', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "address"', async function () { + throw new Error('Not implemented') + }) + + it('should confirm solidity functionality: "mapping"', async function () { + throw new Error('Not implemented') + }) + +}) diff --git a/test/solidity/scoping/scoping.js b/test/solidity/scoping/scoping.js new file mode 100644 index 000000000..f1572b42a --- /dev/null +++ b/test/solidity/scoping/scoping.js @@ -0,0 +1,39 @@ +/*- + * + * Hedera JSON RPC Relay - Hardhat Example + * + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * 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. + * + */ + +const { expect } = require('chai') +const { ethers } = require('hardhat') +const Constants = require('../../constants') + +describe('Scoping tests', () => { + let contract + + before(async () => { + const factory = await ethers.getContractFactory(Constants.Contract.Scoping) + contract = await factory.deploy() + }) + + it('should verify the solidity functionality: "scoping"', async () => { + await contract.minimalScoping(); + const resReassign = await contract.reassign(); + + expect(resReassign).to.equal(2); + }) +})