Skip to content

Commit

Permalink
P-872 basic tests for contracts (#2845)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
0xverin committed Jul 5, 2024
1 parent 8e64491 commit fc1994c
Show file tree
Hide file tree
Showing 17 changed files with 703 additions and 11 deletions.
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
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";
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

0 comments on commit fc1994c

Please sign in to comment.