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

[TS] Updated the gas fee payer example to adopt the new API #9499

Merged
merged 1 commit into from
Aug 5, 2023

Conversation

junkil-park
Copy link
Contributor

@junkil-park junkil-park commented Aug 4, 2023

Description

  • Updated the gas fee payer example to adopt the new API of aptos SDK v. 1.17.0
  • Simplifies the flow significantly

Test Plan

pnpm run gas_fee_payer

Copy link
Contributor

@0xmaayan 0xmaayan left a comment

Choose a reason for hiding this comment

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

LGTM

@junkil-park junkil-park requested a review from hardsetting August 4, 2023 20:00
@@ -16,6 +16,7 @@ import {
} from "aptos";
import { NODE_URL, FAUCET_URL } from "./common";
import { assert } from "console";
import * as Gen from "../../src/generated";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@0xmaayan , is there a better way to import this than using a relative path like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can import 'Type' and then use it 'Type.'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied. Thank you!

@xbtmatt
Copy link
Contributor

xbtmatt commented Aug 4, 2023

Great! A lot simpler :D

Would be nice to have alice and bob's balance tracked from before and after and then print out the gas fees so you can see that Alice's balance didn't change and Bob's did, in the same amount as the gas fees paid:

  const aliceBalanceBefore = await getBalance(alice);
  const bobBalanceBefore = await getBalance(bob);
  console.log(`Alice's balance: ${aliceBalanceBefore} octas`);
  console.log(`Bob's balance: ${bobBalanceBefore} octas`);
  
  // ... submit tx
  
  const response = await client.waitForTransactionWithResult(txnHash, { checkSuccess: true });
  const { gas_used, gas_unit_price } = response as any;
  
  // ... print token amt
  
  // Check that Alice did not pay the fee, but Bob did.
  const aliceBalanceAfter = await getBalance(alice);
  const bobBalanceAfter = await getBalance(bob);
  console.log(`Alice's balance: ${aliceBalanceAfter} octas`);
  console.log(`Bob's balance: ${bobBalanceAfter} octas`);

  console.log(
    "\n=== Check Bob and Alice's balance changes ===\n" +
      `Alice's balance change: ${aliceBalanceBefore - aliceBalanceAfter} octas\n` +
      `Bob's balance change: ${bobBalanceBefore - bobBalanceAfter} octas\n` +
      `The gas fees were: ${gas_used * gas_unit_price} octas`,
  );

@junkil-park junkil-park force-pushed the jpark/gas-fee-payer-example-update branch from 9454da4 to 3101f80 Compare August 4, 2023 23:45
@junkil-park junkil-park requested a review from saharct as a code owner August 4, 2023 23:45
@junkil-park junkil-park force-pushed the jpark/gas-fee-payer-example-update branch from 3101f80 to f50909d Compare August 4, 2023 23:46
@junkil-park junkil-park enabled auto-merge (squash) August 4, 2023 23:46
@junkil-park junkil-park disabled auto-merge August 4, 2023 23:46
- Updated the gas fee payer example to adopt the new API of aptos SDK v. 1.17.0
- Simplifies the flow significantly
@junkil-park junkil-park force-pushed the jpark/gas-fee-payer-example-update branch from f50909d to da71f7b Compare August 4, 2023 23:49
@junkil-park
Copy link
Contributor Author

junkil-park commented Aug 4, 2023

Great! A lot simpler :D

Would be nice to have alice and bob's balance tracked from before and after and then print out the gas fees so you can see that Alice's balance didn't change and Bob's did, in the same amount as the gas fees paid:

  const aliceBalanceBefore = await getBalance(alice);
  const bobBalanceBefore = await getBalance(bob);
  console.log(`Alice's balance: ${aliceBalanceBefore} octas`);
  console.log(`Bob's balance: ${bobBalanceBefore} octas`);
  
  // ... submit tx
  
  const response = await client.waitForTransactionWithResult(txnHash, { checkSuccess: true });
  const { gas_used, gas_unit_price } = response as any;
  
  // ... print token amt
  
  // Check that Alice did not pay the fee, but Bob did.
  const aliceBalanceAfter = await getBalance(alice);
  const bobBalanceAfter = await getBalance(bob);
  console.log(`Alice's balance: ${aliceBalanceAfter} octas`);
  console.log(`Bob's balance: ${bobBalanceAfter} octas`);

  console.log(
    "\n=== Check Bob and Alice's balance changes ===\n" +
      `Alice's balance change: ${aliceBalanceBefore - aliceBalanceAfter} octas\n` +
      `Bob's balance change: ${bobBalanceBefore - bobBalanceAfter} octas\n` +
      `The gas fees were: ${gas_used * gas_unit_price} octas`,
  );

Thank you for the nice suggestion! I updated it to display the gas fee usage per transaction!

@junkil-park junkil-park enabled auto-merge (squash) August 4, 2023 23:51
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

✅ Forge suite compat success on aptos-node-v1.5.1 ==> da71f7b6fc1b4518bf5d73f4ad7b6167326369ce

Compatibility test results for aptos-node-v1.5.1 ==> da71f7b6fc1b4518bf5d73f4ad7b6167326369ce (PR)
1. Check liveness of validators at old version: aptos-node-v1.5.1
compatibility::simple-validator-upgrade::liveness-check : committed: 4601 txn/s, latency: 7091 ms, (p50: 7200 ms, p90: 10200 ms, p99: 12600 ms), latency samples: 174840
2. Upgrading first Validator to new version: da71f7b6fc1b4518bf5d73f4ad7b6167326369ce
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 1827 txn/s, latency: 15911 ms, (p50: 18600 ms, p90: 22200 ms, p99: 22300 ms), latency samples: 93200
3. Upgrading rest of first batch to new version: da71f7b6fc1b4518bf5d73f4ad7b6167326369ce
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 1844 txn/s, latency: 15606 ms, (p50: 18700 ms, p90: 22000 ms, p99: 22500 ms), latency samples: 92200
4. upgrading second batch to new version: da71f7b6fc1b4518bf5d73f4ad7b6167326369ce
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 3081 txn/s, latency: 9593 ms, (p50: 10200 ms, p90: 12900 ms, p99: 14100 ms), latency samples: 135600
5. check swarm health
Compatibility test for aptos-node-v1.5.1 ==> da71f7b6fc1b4518bf5d73f4ad7b6167326369ce passed
Test Ok

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

✅ Forge suite realistic_env_max_load success on da71f7b6fc1b4518bf5d73f4ad7b6167326369ce

two traffics test: inner traffic : committed: 6068 txn/s, latency: 6470 ms, (p50: 6000 ms, p90: 8400 ms, p99: 12900 ms), latency samples: 2621660
two traffics test : committed: 100 txn/s, latency: 2796 ms, (p50: 2800 ms, p90: 3300 ms, p99: 4200 ms), latency samples: 1820
Max round gap was 1 [limit 4] at version 1375989. Max no progress secs was 3.512635 [limit 10] at version 1375989.
Test Ok

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

✅ Forge suite framework_upgrade success on aptos-node-v1.5.1 ==> da71f7b6fc1b4518bf5d73f4ad7b6167326369ce

Compatibility test results for aptos-node-v1.5.1 ==> da71f7b6fc1b4518bf5d73f4ad7b6167326369ce (PR)
Upgrade the nodes to version: da71f7b6fc1b4518bf5d73f4ad7b6167326369ce
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 4502 txn/s, latency: 7230 ms, (p50: 7800 ms, p90: 9900 ms, p99: 12500 ms), latency samples: 166600
5. check swarm health
Compatibility test for aptos-node-v1.5.1 ==> da71f7b6fc1b4518bf5d73f4ad7b6167326369ce passed
Test Ok

@junkil-park junkil-park merged commit 26ec3c5 into main Aug 5, 2023
@junkil-park junkil-park deleted the jpark/gas-fee-payer-example-update branch August 5, 2023 00:28
xbtmatt pushed a commit that referenced this pull request Aug 13, 2023
- Updated the gas fee payer example to adopt the new API of aptos SDK v. 1.17.0
- Simplifies the flow significantly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants