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

feat: Added spending plans for testing on testnet. #3136

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"axios-mock-adapter": "^1.20.0",
"chai-as-promised": "^7.1.1",
"chai-exclude": "^2.1.1",
"env-cmd": "^10.1.0",
"eslint": "^8.48.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
Expand Down Expand Up @@ -79,7 +80,8 @@
"test": "npx lerna run test",
"openrpctest": "ts-mocha packages/relay/tests/lib/openrpc.spec.ts --exit",
"bump-version": "SEM_VER=${npm_config_semver} SNAPSHOT=${npm_config_snapshot} node scripts/.bump-version.js",
"prepare": "husky install"
"prepare": "husky install",
"create-alias-accounts": "env-cmd node ./scripts/createAliasAccounts.js"
},
"dependencies": {
"@ethereumjs/rlp": "^5.0.2",
Expand All @@ -91,8 +93,8 @@
"lerna": "^8.1.8",
"pino": "^7.11.0",
"pino-pretty": "^7.6.1",
"prom-client": "^14.0.1",
"pnpm": "^8.7.1",
"prom-client": "^14.0.1",
"redis": "^4.7.0"
},
"overrides": {
Expand Down
28 changes: 28 additions & 0 deletions packages/server/tests/testnetSpendingPlans.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"id": "c758c095-342c-4607-9db5-867d7e90ab9d",
"name": "partner name",
"ethAddresses": ["0x7d102fe71af42790fe31b126c1f49766376ca2b5", "0x4ad27ba9330cb336b0ee38bfb5b86da015500342"],
"ipAddresses": ["127.0.0.1", "128.0.0.1"],
"subscriptionTier": "PRIVILEGED"
},
{
"id": "a68488b0-6f7d-44a0-87c1-774ad64615f2",
"name": "some other partner that has given us only eth addresses",
"ethAddresses": ["0x40183ec818c1826114767391989ff2eaebc2b91e", "0x1fd56166627bee3fc51c0918451e3391f463219c"],
"subscriptionTier": "PRIVILEGED"
},
{
"id": "af13d6ed-d676-4d33-8b9d-cf05d1ad7134",
"name": "supported project name",
"ethAddresses": ["0x421e224dfe6717d94a03ce23741c2d7c6009f2dc", "0x149294f355f62827748988071de70ab195d0eb23"],
"ipAddresses": ["129.0.0.1", "130.0.0.1"],
"subscriptionTier": "EXTENDED"
},
{
"id": "7f665aa3-6b73-41d7-bf9b-92d04cdab96b",
"name": "some other supported project that has given us only ip addresses",
"ipAddresses": ["131.0.0.1", "132.0.0.1"],
"subscriptionTier": "EXTENDED"
}
]
77 changes: 77 additions & 0 deletions scripts/createAliasAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2022-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.
*
*/
const { Client, PrivateKey, TransferTransaction, AccountId, Hbar } = require('@hashgraph/sdk');
const { exit } = require('process');

const operatorAccountId = process.env.OPERATOR_ID_MAIN;
const operatorPrivateKey = process.env.OPERATOR_KEY_MAIN;


if (!operatorAccountId || !operatorPrivateKey) {
throw new Error('Operator ID and Private Key must be set.');
}

let client;
if(process.env.HEDERA_NETWORK === 'testnet') {
client = Client.forTestnet();
} else {
client = Client.forPreviewnet();
}

client.setOperator(operatorAccountId, operatorPrivateKey);

const numberOfAccounts = 4;

// Initial balance for each new account (in tinybars)
const initialBalanceTinybar = Hbar.fromTinybars(1000000000); // Equivalent to 10 HBAR

async function main() {

for (let i = 1; i <= numberOfAccounts; i++) {
console.log(`\n=== Creating Alias Account ${i} ===`);

const privateKey = PrivateKey.generateECDSA();
const publicKey = privateKey.publicKey;

console.log(`Generated ECDSA Private Key: ${privateKey.toStringRaw()}`);
console.log(`Generated ECDSA Public Key: ${publicKey.toStringRaw()}`);

const ethereumAddress = publicKey.toEthereumAddress();

console.log(`Ethereum Address: 0x${ethereumAddress.toString()}`);

const aliasAccountId = AccountId.fromEvmAddress(0, 0, ethereumAddress);

const transferTx = await new TransferTransaction()
.addHbarTransfer(operatorAccountId, initialBalanceTinybar.negated())
.addHbarTransfer(aliasAccountId, initialBalanceTinybar)
.execute(client);

const receipt = await transferTx.getReceipt(client);
console.log(`Transfer Transaction Status: ${receipt.status.toString()}`);
Comment on lines +50 to +68
Copy link
Member

Choose a reason for hiding this comment

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

This works fine, but I've seen the AccountCreateTransaction API used before, like this:

TransactionResponse newAccount = new AccountCreateTransaction()
     .setKey(newAccountPublicKey)
     .setInitialBalance(Hbar.fromTinybars(1000))
     .execute(client);

Just a suggestion—no need to change anything!


}

exit();
}

main().catch((error) => {
console.error('Error creating alias accounts:', error);
});
Loading