Skip to content

Commit

Permalink
test: added new test suite for PrngSystemContract (#416) (#417)
Browse files Browse the repository at this point in the history
* test: added new test suite for PrngSystemContract

Signed-off-by: Logan Nguyen <[email protected]>

* test: added PrngSystemContract to CI tasks

Signed-off-by: Logan Nguyen <[email protected]>

* update(test): checked PseudoRandomSeed against HashZero

Signed-off-by: Logan Nguyen <[email protected]>

* update: added expect(result).to.exist

Signed-off-by: Logan Nguyen <[email protected]>

---------

Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node authored Sep 21, 2023
1 parent 77e6ade commit 66ffc3a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand Down
2 changes: 2 additions & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Events = {
GetNonFungibleTokenInfo: 'GetNonFungibleTokenInfo',
TinyBars: 'TinyBars',
TinyCents: 'TinyCents',
PseudoRandomSeed: 'PseudoRandomSeed',
}

const Path = {
Expand Down Expand Up @@ -97,6 +98,7 @@ const Contract = {
ERC20SnapshotMock: 'ERC20SnapshotMock',
HRCContract: 'HRCContract',
ExchangeRateMock: 'ExchangeRateMock',
PrngSystemContract: 'PrngSystemContract',
}

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

0 comments on commit 66ffc3a

Please sign in to comment.