Skip to content

Commit

Permalink
Benchmark script update (#101)
Browse files Browse the repository at this point in the history
* test: update benchmark

* refactor: remove redundant comment
  • Loading branch information
MikkySnow authored Jun 13, 2024
1 parent e1d2adb commit 4c582be
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 60 deletions.
1 change: 1 addition & 0 deletions scripts/local-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ echo "cup hip eyebrow flock slogan filter gas tent angle purpose rose setup" | s

swisstronikd init $MONIKER -o --chain-id $CHAINID --home "$HOMEDIR"

jq '.app_state["feemarket"]["params"]["base_fee"]="7"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["staking"]["params"]["bond_denom"]="aswtr"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["staking"]["params"]["unbonding_time"]="1s"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["crisis"]["constant_fee"]["denom"]="aswtr"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Expand Down
3 changes: 0 additions & 3 deletions sgxvm/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ impl<'state> ExtendedBackend for FFIBackend<'state> {
storage,
..
} => {
// Reset storage is ignored since storage cannot be efficiently reset as this
// would require iterating over storage keys

// Update account balance and nonce
let previous_account_data = self.state.get_account(&address);

Expand Down
2 changes: 1 addition & 1 deletion tests/tx-benchmark/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_RPC=http://127.0.0.1:8545
FIRST_PRIVATE_KEY=C516DC17D909EFBB64A0C4A9EE1720E10D47C1BF3590A257D86EEB5FFC644D43
FIRST_PRIVATE_KEY=DBE7E6AE8303E055B68CEFBF01DEC07E76957FF605E5333FA21B6A8022EA7B55
82 changes: 42 additions & 40 deletions tests/tx-benchmark/contracts/ERC20Token.json

Large diffs are not rendered by default.

39 changes: 24 additions & 15 deletions tests/tx-benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const { encryptDataField } = require('@swisstronik/swisstronik.js')
const provider = new ethers.providers.JsonRpcProvider(process.env.NODE_RPC || 'http://localhost:8545')
const initialWallet = new ethers.Wallet(process.env.FIRST_PRIVATE_KEY, provider)

const NUM_TESTING_ACCOUNTS = 20
const INIT_WALLET_SWTR_BALANCE = ethers.utils.parseEther("0.01")
const INIT_WALLET_TOKEN_BALANCE = 1000000000
const NUM_TESTING_ACCOUNTS = 50

async function transferERC20Token(sender, receiverAddress, tokenContract, amountToTransfer) {
try {
Expand All @@ -27,7 +29,8 @@ async function deployERC20() {
const metadata = JSON.parse(fs.readFileSync('contracts/ERC20Token.json'))
const factory = new ethers.ContractFactory(metadata.abi, metadata.bytecode, initialWallet);

const contract = await factory.deploy('test token', 'TT', 1000000000);
const transferAmount = INIT_WALLET_SWTR_BALANCE.mul(NUM_TESTING_ACCOUNTS);
const contract = await factory.deploy({value: transferAmount});
await contract.deployed()

return contract
Expand All @@ -46,8 +49,8 @@ async function sendShieldedTransaction(signer, destination, data, value) {
to: destination,
data: encryptedData,
value,
gasLimit: 300_000,
gasPrice: 7 // We're using 0 gas price in tests
// gasLimit: 300_000,
// gasPrice: 7 // We're using 0 gas price in tests
})
}

Expand All @@ -68,22 +71,28 @@ async function main() {
const tokenContract = await deployERC20()
console.log(`ERC20 deployed with address: ${tokenContract.address}`)

// prepare NUM_TESTING_ACCOUNTS accounts and prefund it
console.log('Initializing wallets')
const wallets = []
for (let i = 0; i < NUM_TESTING_ACCOUNTS; i++) {
const wallet = ethers.Wallet.createRandom().connect(provider)

const tx = await initialWallet.sendTransaction({
to: wallet.address,
value: "1000000000"
})
await tx.wait()

// Transfer ERC20 token
await transferERC20Token(initialWallet, wallet.address, tokenContract, 10000)
console.log("Wallet", (i + 1), "is ready among", NUM_TESTING_ACCOUNTS, "wallets. Address:", wallet.address)
wallets.push(wallet)
}
const walletAddresses = wallets.map((wallet) => wallet.address)
const amounts = [...Array(NUM_TESTING_ACCOUNTS)].map(() => INIT_WALLET_SWTR_BALANCE)
const swtrTransferTx = await sendShieldedTransaction(
initialWallet,
tokenContract.address,
tokenContract.interface.encodeFunctionData("bulkTransfer", [walletAddresses, amounts])
)
await swtrTransferTx.wait()

const tokenAmounts = [...Array(NUM_TESTING_ACCOUNTS)].map(() => INIT_WALLET_TOKEN_BALANCE)
const tokenTransferTx = await sendShieldedTransaction(
initialWallet,
tokenContract.address,
tokenContract.interface.encodeFunctionData("bulkMint", [walletAddresses, tokenAmounts])
)
await tokenTransferTx.wait()

console.log('Wallets are ready')

Expand Down
2 changes: 1 addition & 1 deletion tests/tx-benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node index.js"
},
"author": "",
"license": "ISC",
Expand Down

0 comments on commit 4c582be

Please sign in to comment.