From 66ffc3a170fe18c1b8637ed77b9a6ef4332fe6da Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Thu, 21 Sep 2023 11:08:51 -0500 Subject: [PATCH] test: added new test suite for PrngSystemContract (#416) (#417) * test: added new test suite for PrngSystemContract Signed-off-by: Logan Nguyen * test: added PrngSystemContract to CI tasks Signed-off-by: Logan Nguyen * update(test): checked PseudoRandomSeed against HashZero Signed-off-by: Logan Nguyen * update: added expect(result).to.exist Signed-off-by: Logan Nguyen --------- Signed-off-by: Logan Nguyen --- .github/workflows/tests.yml | 6 +++ test/constants.js | 2 + test/util-precompile/PrngSystemContract.js | 47 ++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/util-precompile/PrngSystemContract.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cab9c7a36..29ae3c11a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,6 +95,12 @@ jobs: with: testfilter: ShanghaiOpcodes + PrngSystemContract: + name: PrngSystemContract Test Suite + uses: ./.github/workflows/test-workflow.yml + with: + testfilter: PrngSystemContract + PublishResults: name: Publish Results if: ${{ !cancelled() }} diff --git a/test/constants.js b/test/constants.js index 57e94e962..88403fefc 100644 --- a/test/constants.js +++ b/test/constants.js @@ -55,6 +55,7 @@ const Events = { GetNonFungibleTokenInfo: 'GetNonFungibleTokenInfo', TinyBars: 'TinyBars', TinyCents: 'TinyCents', + PseudoRandomSeed: 'PseudoRandomSeed', } const Path = { @@ -97,6 +98,7 @@ const Contract = { ERC20SnapshotMock: 'ERC20SnapshotMock', HRCContract: 'HRCContract', ExchangeRateMock: 'ExchangeRateMock', + PrngSystemContract: 'PrngSystemContract', } const CALL_EXCEPTION = 'CALL_EXCEPTION' diff --git a/test/util-precompile/PrngSystemContract.js b/test/util-precompile/PrngSystemContract.js new file mode 100644 index 000000000..63f586fbd --- /dev/null +++ b/test/util-precompile/PrngSystemContract.js @@ -0,0 +1,47 @@ +/*- + * + * 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('PrngSystemContract tests', function () { + let prngSystemContract + + before(async function () { + const factory = await ethers.getContractFactory( + Constants.Contract.PrngSystemContract + ) + + prngSystemContract = await factory.deploy() + }) + + it('should be able to execute getPseudorandomSeed to generate a pseudo random seed', async function () { + const tx = await prngSystemContract.getPseudorandomSeed() + const txReceipt = await tx.wait() + + const result = txReceipt.events.filter( + (e) => e.event === Constants.Events.PseudoRandomSeed + )[0].args[0] + + expect(result).to.exist + expect(result).to.not.hexEqual(ethers.constants.HashZero) + }) +})