Skip to content

Commit 517fe40

Browse files
author
Piotr Węgrzyn
committed
unit tests
1 parent 0754181 commit 517fe40

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

.github/workflows/linter_eth.yml renamed to .github/workflows/eth_linter.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ on:
88
jobs:
99
analyze:
1010
runs-on: ubuntu-latest
11+
name: A job to run linter
1112
steps:
12-
- name: Checkout repository
13+
- name: Checkout
1314
uses: actions/checkout@v4
1415
- name: Linter analysis with Slither
1516
uses: crytic/slither-action@v0.4.0

.github/workflows/eth_unit_tests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unit tests for Cyrograf ETH
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
paths: [ 'eth/**' ]
7+
8+
jobs:
9+
unit_tests:
10+
runs-on: ubuntu-latest
11+
name: A job to run sample solidity tests
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Environment Setup
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 14.17.6
19+
- name: Run SUT action with default provider
20+
uses: EthereumRemix/sol-test@v1.2
21+
with:
22+
test-path: 'eth/tests/'
23+
compiler-version: '0.8.26'

.github/workflows/deploy_ui.yml renamed to .github/workflows/ui_deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
name: Pin and publish
1515
steps:
16-
- name: Checkout repository
16+
- name: Checkout
1717
uses: actions/checkout@v4
1818
- name: IPFS Pin & Publish
1919
id: IPFS

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode/
22
**/.states/
3-
**/artifacts/
3+
**/artifacts/
4+
**/.deps/

eth/tests/cyrograf_test.sol

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
pragma solidity >=0.8.26;
4+
5+
import "remix_tests.sol";
6+
import "remix_accounts.sol";
7+
import "../cyrograf.sol";
8+
9+
contract CyrografTestSuite {
10+
Cyrograf cyrograf;
11+
12+
// Setup function to initialize the contract before tests run
13+
function beforeEach() public {
14+
cyrograf = new Cyrograf();
15+
}
16+
17+
function testInitialBackground() public {
18+
Cyrograf.Background memory got = cyrograf.getBackground();
19+
20+
Assert.equal(got.author, address(this), "The author should be the deployer");
21+
22+
Assert.equal(got.topLeft.x, uint8(0), "Top left X should be 0");
23+
Assert.equal(got.topLeft.y, uint8(0), "Top left Y should be 0");
24+
Assert.equal(got.topLeft.z, uint8(0), "Top left Z should be 0");
25+
26+
Assert.equal(got.topRight.x, uint8(255), "Top right X should be 255");
27+
Assert.equal(got.topRight.y, uint8(255), "Top right Y should be 255");
28+
Assert.equal(got.topRight.z, uint8(255), "Top right Z should be 255");
29+
}
30+
31+
function testSetAndGetBackground() public {
32+
cyrograf.setBackground(Cyrograf.RGB(128, 64, 32), Cyrograf.RGB(200, 150, 100));
33+
34+
Cyrograf.Background memory got = cyrograf.getBackground();
35+
36+
Assert.equal(got.author, address(this), "The author should be the caller");
37+
38+
Assert.equal(got.topLeft.x, uint8(128), "North west X should be updated");
39+
Assert.equal(got.topLeft.y, uint8(64), "North west Y should be updated");
40+
Assert.equal(got.topLeft.z, uint8(32), "North west Z should be updated");
41+
42+
Assert.equal(got.topRight.x, uint8(200), "South east X should be updated");
43+
Assert.equal(got.topRight.y, uint8(150), "South east Y should be updated");
44+
Assert.equal(got.topRight.z, uint8(100), "South east Z should be updated");
45+
}
46+
}
47+

0 commit comments

Comments
 (0)