Skip to content

Commit

Permalink
Adding TypeOps Solidity Test Coverage (#526)
Browse files Browse the repository at this point in the history
* Adding TypeOps Solidity Test Coverage

Signed-off-by: Alfredo Gutierrez <[email protected]>

* using tag solidityevmequiv1 instead ofsolidityevmequiv2

Signed-off-by: Alfredo Gutierrez <[email protected]>

* adding blank spaces at EOF

Signed-off-by: Alfredo Gutierrez <[email protected]>

---------

Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 authored Oct 24, 2023
1 parent ab035ef commit 1b45c1e
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
14 changes: 14 additions & 0 deletions contracts/solidity/typeops/AnotherContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "./MyInterface.sol";

contract AnotherContract is MyInterface {
function sayHelloWorld() external pure returns (string memory) {
return "Hello World";
}

function myFunction() external pure override returns (uint) {
return 123;
}
}
7 changes: 7 additions & 0 deletions contracts/solidity/typeops/MyInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

// Define an interface
interface MyInterface {
function myFunction() external pure returns (uint);
}
57 changes: 57 additions & 0 deletions contracts/solidity/typeops/TypeOps.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "./MyInterface.sol";
import "./AnotherContract.sol";

contract TypeOps {

// type(C).name where C is a contract
function typeContractName() external pure returns (string memory) {
// get the contract name
return type(TypeOps).name;
}

// `type(C).creationCode` where `C` is a contract
function typeContractCreationCode() external pure returns (bytes memory) {
// get the contract creation code
return type(AnotherContract).creationCode;
}

// `type(C).runtimeCode` where `C` is a contract
function typeContractRuntimeCode() external pure returns (bytes memory) {
// get the contract runtime code
return type(AnotherContract).runtimeCode;
}

// type(I).interfaceId where I is an interface
function typeInterfaceId() external pure returns (bytes4) {
// get the interface id
return type(MyInterface).interfaceId;
}

// `type(I).min` where `T` is an integer type
function typeIntegerMin() external pure returns (int) {
// get the minimum value of int
return type(int).min;
}

// `type(T).max` where `T` is an integer type
function typeIntegerMax() external pure returns (int) {
// get the minimum value of int
return type(int).max;
}

// `type(T).min` where `T` is an unsigned integer type
function typeUintMin() external pure returns (uint) {
// get the minimum value of uint
return type(uint).min;
}

// `type(T).max` where `T` is an unsigned integer type
function typeUintMax() external pure returns (uint) {
// get the maximum value of uint
return type(uint).max;
}

}
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const Path = {
HIP583_ERC20Mock: 'contracts/hip-583/ERC20Mock.sol:ERC20Mock',
HIP583_ERC721Mock: 'contracts/hip-583/ERC721Mock.sol:ERC721Mock',
HRC: 'contracts/hrc/HRC.sol:HRC',
TYPE_OPS: 'contracts/solidity/typeops/TypeOps.sol:TypeOps',
}

const Contract = {
Expand Down
90 changes: 90 additions & 0 deletions test/solidity/typeops/TypeOps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*-
*
* Hedera Smart Contracts
*
* 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('@solidityevmequiv1 TypeOps Test Suite', function () {
let cryptoMathContract, provider, signers;

before(async function () {
signers = await ethers.getSigners();
provider = ethers.getDefaultProvider();
const factory = await ethers.getContractFactory(Constants.Path.TYPE_OPS);
typeOpsContract = await factory.deploy({ gasLimit: 15000000 });
});

// typeContractName
it('retrieve contract name using Type name', async function () {
const res = await typeOpsContract.typeContractName();
expect(res).to.equal('TypeOps');
});

// typeContractCreationCode
it('retrieve contract creation code using Type(Contract)', async function () {
const expectedCreationCode = '0x608060405234801561001057600080fd5b5060fb8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806345773e4e146037578063c3780a3a14606b575b600080fd5b604080518082018252600b81526a12195b1b1bc815dbdc9b1960aa1b60208201529051606291906079565b60405180910390f35b604051607b81526020016062565b600060208083528351808285015260005b8181101560a457858101830151858201604001528201608a565b506000604082860101526040601f19601f830116850101925050509291505056fea2646970667358221220816f65101f202507900f94cffe67dfa203d792518dc1f8eace7f3511d9dd8da964736f6c63430008140033';
const res = await typeOpsContract.typeContractCreationCode();
expect(res).to.equal(expectedCreationCode);
});

// typeContractRuntimeCode
it('retrieve contract runtime code using Type(Contract)', async function () {
const expectedRuntimeCode = '0x6080604052348015600f57600080fd5b506004361060325760003560e01c806345773e4e146037578063c3780a3a14606b575b600080fd5b604080518082018252600b81526a12195b1b1bc815dbdc9b1960aa1b60208201529051606291906079565b60405180910390f35b604051607b81526020016062565b600060208083528351808285015260005b8181101560a457858101830151858201604001528201608a565b506000604082860101526040601f19601f830116850101925050509291505056fea2646970667358221220816f65101f202507900f94cffe67dfa203d792518dc1f8eace7f3511d9dd8da964736f6c63430008140033';
const res = await typeOpsContract.typeContractRuntimeCode();
expect(res).to.equal(expectedRuntimeCode);
});

// typeInterfaceId
it('retrieve contract interface id using Type(Contract)', async function () {
const expectedInterfaceId = '0xc3780a3a';
const res = await typeOpsContract.typeInterfaceId();
expect(res).to.equal(expectedInterfaceId);
});

// typeIntegerMin
it('retrieve contract integer min using Type(Integer)', async function () {
const expectedIntegerMin = '-57896044618658097711785492504343953926634992332820282019728792003956564819968';
const res = await typeOpsContract.typeIntegerMin();
expect(res).to.equal(expectedIntegerMin);
});

// typeIntegerMax
it('retrieve contract integer max using Type(Integer)', async function () {
const expectedIntegerMax = '57896044618658097711785492504343953926634992332820282019728792003956564819967';
const res = await typeOpsContract.typeIntegerMax();
expect(res).to.equal(expectedIntegerMax);
});

// typeUintMin
it('retrieve contract uint min using Type(Uint)', async function () {
const expectedUintMin = '0';
const res = await typeOpsContract.typeUintMin();
expect(res).to.equal(expectedUintMin);
});

// typeUintMax
it('retrieve contract uint max using Type(Uint)', async function () {
const expectedUintMax = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
const res = await typeOpsContract.typeUintMax();
expect(res).to.equal(expectedUintMax);
});


});

0 comments on commit 1b45c1e

Please sign in to comment.