-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solo smoke test to test flow (#905)
Signed-off-by: Jeffrey Tang <[email protected]> Signed-off-by: Jeromy Cannon <[email protected]> Co-authored-by: Jeromy Cannon <[email protected]>
- Loading branch information
1 parent
b378937
commit 79410f0
Showing
5 changed files
with
269 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
# | ||
# This script should be called after solo has been deployed with mirror node and relay node deployed, | ||
# and should be called from the root of the solo repository | ||
# | ||
# This uses solo account creation function to repeatedly generate background transactions | ||
# Then run smart contract test, and also javascript sdk sample test to interact with solo network | ||
# | ||
|
||
function_name="" | ||
|
||
function enable_port_forward () | ||
{ | ||
kubectl port-forward -n solo-e2e svc/haproxy-node1-svc 50211:50211 > /dev/null 2>&1 & | ||
kubectl port-forward -n solo-e2e svc/hedera-explorer 8080:80 > /dev/null 2>&1 & | ||
kubectl port-forward -n solo-e2e svc/relay-node1-hedera-json-rpc-relay 7546:7546 > /dev/null 2>&1 & | ||
kubectl port-forward -n solo-e2e svc/mirror-grpc 5600:5600 > /dev/null 2>&1 & | ||
} | ||
|
||
function clone_smart_contract_repo () | ||
{ | ||
echo "Clone hedera-smart-contracts" | ||
if [ -d "hedera-smart-contracts" ]; then | ||
echo "Directory hedera-smart-contracts exists." | ||
else | ||
echo "Directory hedera-smart-contracts does not exist." | ||
git clone https://github.com/hashgraph/hedera-smart-contracts --branch only-erc20-tests | ||
fi | ||
} | ||
|
||
function setup_smart_contract_test () | ||
{ | ||
echo "Setup smart contract test" | ||
cd hedera-smart-contracts | ||
|
||
echo "Remove previous .env file" | ||
rm -f .env | ||
|
||
npm install | ||
npx hardhat compile || return 1: | ||
|
||
echo "Build .env file" | ||
|
||
echo "PRIVATE_KEYS=\"$CONTRACT_TEST_KEYS\"" > .env | ||
echo "RETRY_DELAY=5000 # ms" >> .env | ||
echo "MAX_RETRY=5" >> .env | ||
cat .env | ||
cd - | ||
} | ||
|
||
function start_background_transactions () | ||
{ | ||
echo "Start background transaction" | ||
# generate accounts as background traffic for two minutes | ||
# so record stream files can be kept pushing to mirror node | ||
cd solo | ||
npm run solo-test -- account create -n solo-e2e --create-amount 15 > /dev/null 2>&1 & | ||
cd - | ||
} | ||
|
||
function start_contract_test () | ||
{ | ||
cd hedera-smart-contracts | ||
echo "Wait a few seconds for background transactions to start" | ||
sleep 5 | ||
echo "Run smart contract test" | ||
npm run hh:test | ||
result=$? | ||
|
||
cd - | ||
return $result | ||
} | ||
|
||
function create_test_account () | ||
{ | ||
echo "Create test account with solo network" | ||
cd solo | ||
|
||
# create new account and extract account id | ||
npm run solo-test -- account create -n solo-e2e --hbar-amount 100 --generate-ecdsa-key --set-alias > test.log | ||
export OPERATOR_ID=$(grep "accountId" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g') | ||
echo "OPERATOR_ID=${OPERATOR_ID}" | ||
rm test.log | ||
|
||
# get private key of the account | ||
npm run solo-test -- account get -n solo-e2e --account-id ${OPERATOR_ID} --private-key > test.log | ||
export OPERATOR_KEY=$(grep "privateKey" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g') | ||
export CONTRACT_TEST_KEY_ONE=0x$(grep "privateKeyRaw" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g') | ||
echo "CONTRACT_TEST_KEY_ONE=${CONTRACT_TEST_KEY_ONE}" | ||
rm test.log | ||
|
||
npm run solo-test -- account create -n solo-e2e --hbar-amount 100 --generate-ecdsa-key --set-alias > test.log | ||
export SECOND_KEY=$(grep "accountId" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g') | ||
npm run solo-test -- account get -n solo-e2e --account-id ${SECOND_KEY} --private-key > test.log | ||
export CONTRACT_TEST_KEY_TWO=0x$(grep "privateKeyRaw" test.log | awk '{print $2}' | sed 's/"//g'| sed 's/,//g') | ||
echo "CONTRACT_TEST_KEY_TWO=${CONTRACT_TEST_KEY_TWO}" | ||
rm test.log | ||
|
||
export CONTRACT_TEST_KEYS=${CONTRACT_TEST_KEY_ONE},$'\n'${CONTRACT_TEST_KEY_TWO} | ||
export HEDERA_NETWORK="local-node" | ||
|
||
echo "OPERATOR_KEY=${OPERATOR_KEY}" | ||
echo "HEDERA_NETWORK=${HEDERA_NETWORK}" | ||
echo "CONTRACT_TEST_KEYS=${CONTRACT_TEST_KEYS}" | ||
|
||
cd - | ||
} | ||
|
||
function start_sdk_test () | ||
{ | ||
cd solo | ||
node examples/create-topic.js | ||
result=$? | ||
|
||
cd - | ||
return $result | ||
} | ||
|
||
echo "Restart port-forward" | ||
task helper:clean:port-forward | ||
enable_port_forward | ||
|
||
|
||
echo "Change to parent directory" | ||
cd ../ | ||
create_test_account | ||
clone_smart_contract_repo | ||
setup_smart_contract_test | ||
start_background_transactions | ||
start_contract_test | ||
start_sdk_test | ||
echo "Sleep a while to wait background transactions to finish" | ||
sleep 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the ""License""); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an ""AS IS"" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import {Wallet, LocalProvider, TopicCreateTransaction, TopicMessageSubmitTransaction} from '@hashgraph/sdk'; | ||
|
||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
async function main() { | ||
if (process.env.OPERATOR_ID === null || process.env.OPERATOR_KEY === null || process.env.HEDERA_NETWORK === null) { | ||
throw new Error('Environment variables OPERATOR_ID, HEDERA_NETWORK, and OPERATOR_KEY are required.'); | ||
} | ||
|
||
console.log(`Hedera network = ${process.env.HEDERA_NETWORK}`); | ||
const provider = new LocalProvider(); | ||
|
||
const wallet = new Wallet(process.env.OPERATOR_ID, process.env.OPERATOR_KEY, provider); | ||
|
||
try { | ||
console.log('before create topic'); | ||
// create topic | ||
let transaction = await new TopicCreateTransaction().freezeWithSigner(wallet); | ||
transaction = await transaction.signWithSigner(wallet); | ||
console.log('after sign transaction'); | ||
const createResponse = await transaction.executeWithSigner(wallet); | ||
const createReceipt = await createResponse.getReceiptWithSigner(wallet); | ||
|
||
console.log(`topic id = ${createReceipt.topicId.toString()}`); | ||
|
||
// send one message | ||
let topicMessageSubmitTransaction = await new TopicMessageSubmitTransaction({ | ||
topicId: createReceipt.topicId, | ||
message: 'Hello World', | ||
}).freezeWithSigner(wallet); | ||
topicMessageSubmitTransaction = await topicMessageSubmitTransaction.signWithSigner(wallet); | ||
const sendResponse = await topicMessageSubmitTransaction.executeWithSigner(wallet); | ||
|
||
const sendReceipt = await sendResponse.getReceiptWithSigner(wallet); | ||
|
||
console.log(`topic sequence number = ${sendReceipt.topicSequenceNumber.toString()}`); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
provider.close(); | ||
} | ||
|
||
void main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters