Skip to content

Commit fc1994c

Browse files
authored
P-872 basic tests for contracts (#2845)
* Flattening contracts * fix omports * init tests * add compile.json * fix params * fix assertionId * try encryptWithTeeShieldingKey * fix encryptedSecrets * add ci shell * fmt * add lit-tee-vc-contracts-test * rename * chmod +x * source /root/.bashrc * install git * remove sudo * fix shell scripts * ls * ls one more * ls one more * add volumes * cp contracts&&compile * remove hardcode json * fix entrypoint * fix compilation * try to fix assertionId * testing:cli encrypt * fmt * testing:cli response * testing:create assertionId with secretsEncryptedByCli * check:Is cli encrypt the same as ts encrypt * add sleep * update README * merge assertion tests shell * fix docker yml * identity-linking via cli * remove unused code * add developerCommittee * rename scripts name * add alice to developerCommittee * fix copy-contracts * identity-linking using di call
1 parent 8e64491 commit fc1994c

File tree

17 files changed

+703
-11
lines changed

17 files changed

+703
-11
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ jobs:
648648
- test_name: lit-test-failed-parentchain-extrinsic
649649
- test_name: lit-twitter-identity-test
650650
- test_name: lit-discord-identity-test
651+
- test_name: lit-assertion-contracts-test
652+
651653
steps:
652654
- uses: actions/checkout@v4
653655

node/res/genesis_info/staging.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
],
3232
"developerCommittee": [
3333
"jcRVUU8svEMTtwJjX1HzySNrrVEHVnoAdNAmhnbM8ub5dfbM9",
34-
"jcSQcu5RXtWXKPN78zJogNyqsff1j4ffgoJ2njNcDbZ3qNEh5"
34+
"jcSQcu5RXtWXKPN78zJogNyqsff1j4ffgoJ2njNcDbZ3qNEh5",
35+
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
3536
],
3637
"bootNodes": [
3738
"/dns/parachain-sg-0.staging.litentry.io/tcp/40333/p2p/12D3KooWCnBzJy9w9hQFyiwVG2mADqNaPu3Z6WFThivwnrppdWND"

tee-worker/cli/lit_ts_integration_test.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,29 @@ cd /client-api/sidechain-api
6262
${CLIENT} print-sgx-metadata-raw > prepare-build/litentry-sidechain-metadata.json
6363
echo "update sidechain metadata"
6464

65+
6566
cd /client-api
6667
pnpm install
6768
pnpm run build
6869

69-
cd /ts-tests
70-
pnpm install
70+
if [ "$TEST" = "assertion_contracts.test.ts" ]; then
71+
cd /
72+
ls assertion-contracts/
73+
cp -r assertion-contracts /ts-tests/integration-tests/contracts
74+
75+
cd /ts-tests
76+
curl -L https://foundry.paradigm.xyz | bash
77+
source /root/.bashrc
78+
apt install -y git
79+
foundryup
80+
81+
pnpm install
82+
pnpm --filter integration-tests run compile-contracts
83+
84+
else
85+
cd /ts-tests
86+
pnpm install
87+
88+
fi
89+
7190
NODE_ENV=staging pnpm --filter integration-tests run test $TEST
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
services:
2+
lit-assertion-contracts-test:
3+
image: litentry/identity-cli:latest
4+
container_name: lit-assertion-contracts-test
5+
volumes:
6+
- ../ts-tests:/ts-tests
7+
- ../client-api:/client-api
8+
- ../cli:/usr/local/worker-cli
9+
- ../litentry/core/assertion-build/src/dynamic/contracts:/assertion-contracts
10+
11+
build:
12+
context: ..
13+
dockerfile: build.Dockerfile
14+
target: deployed-client
15+
depends_on:
16+
litentry-node:
17+
condition: service_healthy
18+
litentry-worker-1:
19+
condition: service_healthy
20+
networks:
21+
- litentry-test-network
22+
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh assertion_contracts.test.ts 2>&1' "
23+
restart: "no"
24+
networks:
25+
litentry-test-network:
26+
driver: bridge

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
pragma solidity ^0.8.8;
2020

21-
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/utils/Strings.sol";
21+
import "./openzeppelin/Strings.sol";
2222
import "./libraries/AssertionLogic.sol";
2323
import "./libraries/Http.sol";
2424
import "./libraries/Identities.sol";
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: MIT
2+
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
3+
4+
pragma solidity ^0.8.0;
5+
6+
import "./math/Math.sol";
7+
import "./math/SignedMath.sol";
8+
9+
/**
10+
* @dev String operations.
11+
*/
12+
library Strings {
13+
bytes16 private constant _SYMBOLS = "0123456789abcdef";
14+
uint8 private constant _ADDRESS_LENGTH = 20;
15+
16+
/**
17+
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
18+
*/
19+
function toString(uint256 value) internal pure returns (string memory) {
20+
unchecked {
21+
uint256 length = Math.log10(value) + 1;
22+
string memory buffer = new string(length);
23+
uint256 ptr;
24+
/// @solidity memory-safe-assembly
25+
assembly {
26+
ptr := add(buffer, add(32, length))
27+
}
28+
while (true) {
29+
ptr--;
30+
/// @solidity memory-safe-assembly
31+
assembly {
32+
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
33+
}
34+
value /= 10;
35+
if (value == 0) break;
36+
}
37+
return buffer;
38+
}
39+
}
40+
41+
/**
42+
* @dev Converts a `int256` to its ASCII `string` decimal representation.
43+
*/
44+
function toString(int256 value) internal pure returns (string memory) {
45+
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
46+
}
47+
48+
/**
49+
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
50+
*/
51+
function toHexString(uint256 value) internal pure returns (string memory) {
52+
unchecked {
53+
return toHexString(value, Math.log256(value) + 1);
54+
}
55+
}
56+
57+
/**
58+
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
59+
*/
60+
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
61+
bytes memory buffer = new bytes(2 * length + 2);
62+
buffer[0] = "0";
63+
buffer[1] = "x";
64+
for (uint256 i = 2 * length + 1; i > 1; --i) {
65+
buffer[i] = _SYMBOLS[value & 0xf];
66+
value >>= 4;
67+
}
68+
require(value == 0, "Strings: hex length insufficient");
69+
return string(buffer);
70+
}
71+
72+
/**
73+
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
74+
*/
75+
function toHexString(address addr) internal pure returns (string memory) {
76+
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
77+
}
78+
79+
/**
80+
* @dev Returns true if the two strings are equal.
81+
*/
82+
function equal(string memory a, string memory b) internal pure returns (bool) {
83+
return keccak256(bytes(a)) == keccak256(bytes(b));
84+
}
85+
}

0 commit comments

Comments
 (0)