Skip to content

Commit 1d7b075

Browse files
committed
feat: add pakcage structs #2
1 parent c002f33 commit 1d7b075

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

test/structs/PackageStructs.t.sol

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "forge-std/Test.sol";
5+
import "src/structs/PackageStructs.sol";
6+
7+
contract PackageStructsTest is Test {
8+
9+
function testPackageMeta() public {
10+
PackageStructs.PackageMeta memory meta;
11+
meta.authors = new string[](2);
12+
meta.authors[0] = "Satoshi";
13+
meta.authors[1] = "Vitalik";
14+
meta.license = "MIT";
15+
meta.description = "A safe math library";
16+
meta.keywords = new string[](2);
17+
meta.keywords[0] = "math";
18+
meta.keywords[1] = "library";
19+
meta.website = "https://example.com";
20+
21+
assertEq(meta.authors[0], "Satoshi");
22+
assertEq(meta.license, "MIT");
23+
assertEq(meta.keywords.length, 2);
24+
}
25+
26+
function testCompilerInfo() public {
27+
PackageStructs.CompilerInfo memory compiler;
28+
compiler.name = "solc";
29+
compiler.version = "0.8.0";
30+
31+
assertEq(compiler.name, "solc");
32+
assertEq(compiler.version, "0.8.0");
33+
}
34+
35+
function testContractType() public {
36+
PackageStructs.ContractType memory cType;
37+
cType.contractName = "Wallet";
38+
cType.sourceId = "contracts/Wallet.sol";
39+
cType.compilerIndex = 0;
40+
41+
assertEq(cType.contractName, "Wallet");
42+
assertEq(cType.sourceId, "contracts/Wallet.sol");
43+
}
44+
45+
function testContractInstance() public {
46+
PackageStructs.ContractInstance memory instance;
47+
instance.contractType = "Wallet";
48+
instance.instanceAddress = address(0x1234567890123456789012345678901234567890);
49+
instance.transaction = keccak256("deployment_tx");
50+
instance.blockNumber = 12345;
51+
52+
assertEq(instance.contractType, "Wallet");
53+
assertEq(instance.instanceAddress, address(0x1234567890123456789012345678901234567890));
54+
assertEq(instance.blockNumber, 12345);
55+
}
56+
57+
function testLinkReference() public {
58+
PackageStructs.LinkReference memory ref;
59+
ref.offsets = new uint256[](2);
60+
ref.offsets[0] = 10;
61+
ref.offsets[1] = 50;
62+
ref.length = 20;
63+
ref.name = "SafeMath";
64+
65+
assertEq(ref.offsets[0], 10);
66+
assertEq(ref.offsets[1], 50);
67+
assertEq(ref.length, 20);
68+
assertEq(ref.name, "SafeMath");
69+
}
70+
71+
function testLinkValue() public {
72+
PackageStructs.LinkValue memory val;
73+
val.offsets = new uint256[](1);
74+
val.offsets[0] = 100;
75+
val.valueType = "literal";
76+
val.value = "0x1234";
77+
78+
assertEq(val.offsets[0], 100);
79+
assertEq(val.valueType, "literal");
80+
assertEq(val.value, "0x1234");
81+
}
82+
83+
function testDeploymentInfo() public {
84+
PackageStructs.DeploymentInfo memory deployment;
85+
deployment.chainURI = "blockchain://1/block/0x123abc";
86+
deployment.instances = new PackageStructs.ContractInstance[](1);
87+
88+
deployment.instances[0].contractType = "Token";
89+
deployment.instances[0].instanceAddress = address(0x999);
90+
deployment.instances[0].blockNumber = 99999;
91+
92+
assertEq(deployment.chainURI, "blockchain://1/block/0x123abc");
93+
assertEq(deployment.instances.length, 1);
94+
assertEq(deployment.instances[0].contractType, "Token");
95+
}
96+
97+
function testSourceInfo() public {
98+
PackageStructs.SourceInfo memory source;
99+
source.sourceId = "contracts/Token.sol";
100+
source.content = "ipfs://Qm...";
101+
source.license = "GPL-3.0";
102+
103+
assertEq(source.sourceId, "contracts/Token.sol");
104+
assertEq(source.license, "GPL-3.0");
105+
}
106+
}

0 commit comments

Comments
 (0)