Skip to content

Commit

Permalink
Adding tests for scoping (#476)
Browse files Browse the repository at this point in the history
Adding tests for Scoping

Signed-off-by: Stefan Stefanov <[email protected]>
  • Loading branch information
stefan-stefanooov authored Oct 19, 2023
1 parent 50fa929 commit 46ee829
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
25 changes: 25 additions & 0 deletions contracts/solidity/scoping/Scoping.sol
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const Contract = {
Functions: 'Functions',
FunctionsChild: 'FunctionsChild',
FunctionsParent: 'FunctionsParent',
Scoping: 'Scoping',
}

const CALL_EXCEPTION = 'CALL_EXCEPTION'
Expand Down
39 changes: 39 additions & 0 deletions test/solidity/scoping/scoping.js
Original file line number Diff line number Diff line change
@@ -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);
})
})

0 comments on commit 46ee829

Please sign in to comment.