Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P-872 basic tests for contracts #2845

Merged
merged 48 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d3ea195
Flattening contracts
0xverin Jun 25, 2024
2e88fc5
fix omports
0xverin Jun 25, 2024
dfa6209
init tests
0xverin Jun 25, 2024
0fcdfbb
add compile.json
0xverin Jun 25, 2024
0985212
fix params
0xverin Jun 25, 2024
4b2f338
fix assertionId
0xverin Jun 25, 2024
a754ddc
try encryptWithTeeShieldingKey
0xverin Jun 25, 2024
517247e
fix encryptedSecrets
0xverin Jun 25, 2024
f89dc9b
add ci shell
0xverin Jun 26, 2024
11f5120
Merge branch 'dev' into p-872-basic-tests-for-contracts
0xverin Jun 26, 2024
43e08ac
fmt
0xverin Jun 26, 2024
cc9a2e6
add lit-tee-vc-contracts-test
0xverin Jun 26, 2024
93b1b6a
rename
0xverin Jun 26, 2024
40d28e3
chmod +x
0xverin Jun 26, 2024
652c31a
source /root/.bashrc
0xverin Jun 26, 2024
1d610d6
install git
0xverin Jun 26, 2024
d3a51bf
remove sudo
0xverin Jun 26, 2024
55b5b31
fix shell scripts
0xverin Jun 26, 2024
e564c68
ls
0xverin Jun 26, 2024
0b5e07c
ls one more
0xverin Jun 26, 2024
02fdf52
ls one more
0xverin Jun 26, 2024
96b6e12
add volumes
0xverin Jun 26, 2024
4528895
cp contracts&&compile
0xverin Jun 26, 2024
cbb53d2
remove hardcode json
0xverin Jun 26, 2024
0db373c
fix entrypoint
0xverin Jun 26, 2024
7222141
fix compilation
0xverin Jun 26, 2024
5b8d21d
try to fix assertionId
0xverin Jun 26, 2024
ec52653
testing:cli encrypt
0xverin Jun 26, 2024
1ffe7eb
fmt
0xverin Jun 26, 2024
3be94c5
testing:cli response
0xverin Jun 26, 2024
cc0ef83
testing:create assertionId with secretsEncryptedByCli
0xverin Jun 26, 2024
553e23a
check:Is cli encrypt the same as ts encrypt
0xverin Jun 27, 2024
083a692
add sleep
0xverin Jun 27, 2024
23e74d8
update README
0xverin Jun 27, 2024
11301ba
merge assertion tests shell
0xverin Jun 27, 2024
291d52f
fix docker yml
0xverin Jun 27, 2024
96a8370
identity-linking via cli
0xverin Jun 27, 2024
1a1a00e
Merge branch 'dev' into p-872-basic-tests-for-contracts
0xverin Jun 27, 2024
c278f1d
remove unused code
0xverin Jun 27, 2024
546f2e6
Merge branch 'dev' into p-872-basic-tests-for-contracts
0xverin Jul 1, 2024
57f9ca1
add developerCommittee
0xverin Jul 4, 2024
7575924
rename scripts name
0xverin Jul 4, 2024
7a47838
add alice to developerCommittee
0xverin Jul 4, 2024
e6127d8
Merge branch 'dev' into p-872-basic-tests-for-contracts
0xverin Jul 4, 2024
fc8a2a2
fix copy-contracts
0xverin Jul 4, 2024
bfca5e3
identity-linking using di call
0xverin Jul 4, 2024
fd93583
Merge branch 'dev' into p-872-basic-tests-for-contracts
0xverin Jul 4, 2024
53dcc06
Merge branch 'dev' into p-872-basic-tests-for-contracts
0xverin Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ jobs:
- test_name: lit-test-failed-parentchain-extrinsic
- test_name: lit-twitter-identity-test
- test_name: lit-discord-identity-test
- test_name: lit-assertion-contracts-test

steps:
- uses: actions/checkout@v4

Expand Down
3 changes: 2 additions & 1 deletion node/res/genesis_info/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
],
"developerCommittee": [
"jcRVUU8svEMTtwJjX1HzySNrrVEHVnoAdNAmhnbM8ub5dfbM9",
"jcSQcu5RXtWXKPN78zJogNyqsff1j4ffgoJ2njNcDbZ3qNEh5"
"jcSQcu5RXtWXKPN78zJogNyqsff1j4ffgoJ2njNcDbZ3qNEh5",
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
],
"bootNodes": [
"/dns/parachain-sg-0.staging.litentry.io/tcp/40333/p2p/12D3KooWCnBzJy9w9hQFyiwVG2mADqNaPu3Z6WFThivwnrppdWND"
Expand Down
23 changes: 21 additions & 2 deletions tee-worker/cli/lit_ts_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,29 @@ cd /client-api/sidechain-api
${CLIENT} print-sgx-metadata-raw > prepare-build/litentry-sidechain-metadata.json
echo "update sidechain metadata"


cd /client-api
pnpm install
pnpm run build

cd /ts-tests
pnpm install
if [ "$TEST" = "assertion_contracts.test.ts" ]; then
cd /
ls assertion-contracts/
cp -r assertion-contracts /ts-tests/integration-tests/contracts

cd /ts-tests
curl -L https://foundry.paradigm.xyz | bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it safe to run foreign script that can be changed anytime inside CI ? will it be executed on our hosted runner used for releasing also?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be executed in releasing, plus we don't use a self-hosted runner now : )

But still, should we move the installation part to cli image?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, moving it into cli image would make the scripts cleaner.

source /root/.bashrc
apt install -y git
foundryup

pnpm install
pnpm --filter integration-tests run compile-contracts

else
cd /ts-tests
pnpm install

fi

NODE_ENV=staging pnpm --filter integration-tests run test $TEST
26 changes: 26 additions & 0 deletions tee-worker/docker/lit-assertion-contracts-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
lit-assertion-contracts-test:
image: litentry/identity-cli:latest
container_name: lit-assertion-contracts-test
volumes:
- ../ts-tests:/ts-tests
- ../client-api:/client-api
- ../cli:/usr/local/worker-cli
- ../litentry/core/assertion-build/src/dynamic/contracts:/assertion-contracts

build:
context: ..
dockerfile: build.Dockerfile
target: deployed-client
depends_on:
litentry-node:
condition: service_healthy
litentry-worker-1:
condition: service_healthy
networks:
- litentry-test-network
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh assertion_contracts.test.ts 2>&1' "
restart: "no"
networks:
litentry-test-network:
driver: bridge
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

pragma solidity ^0.8.8;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/utils/Strings.sol";
import "./openzeppelin/Strings.sol";
Copy link
Contributor

@higherordertech higherordertech Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any benefit to hard code this imported code in our repo instead keeping them imported from remote during build time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contracts import via http cannot be decoded and compiled by any compiler, so the contract will be flattened here.
This is supported in remix, but not in solc-related compilers.

Copy link
Contributor

@higherordertech higherordertech Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the contract will be flattened here

Will flattened code break the solc-related complier? Will it break hardhat compiler too (if not we could use hardhat to test and remain the import from source maybe)?
I feel if we keep import from source it will be much easier to maintain. So trying to see if any workaround to not to copy them in our own repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardhat does not support compiling with HTTP imports, only ESM import mode is supported.
The reason for flattening it is because consider that someone will compile in remix, otherwise we can unify esm import.

import "./libraries/AssertionLogic.sol";
import "./libraries/Http.sol";
import "./libraries/Identities.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;

/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}

/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}

/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}

/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}

/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}

/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
Loading