-
Notifications
You must be signed in to change notification settings - Fork 193
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(evm): use atto denomination for the wei units in the EVM so that NIBI is "ether" to clients #1985
Merged
Merged
feat(evm): use atto denomination for the wei units in the EVM so that NIBI is "ether" to clients #1985
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1f0d8d0
refactor: remove unused vars. improve error clarity for testnetwork/New
Unique-Divine 3335463
refactor: use pebbledb as the test db
Unique-Divine e106002
changelog
Unique-Divine a1c5782
refactor(statedb): separate Account and AccountWei to have state obje…
Unique-Divine cd9642b
math functions for unibi and wei
Unique-Divine 9cd1edf
chore: wei unit migration
Unique-Divine 18995b6
test(statedb): complete the wei-based account migration. Remove all m…
Unique-Divine 4419067
test(statedb_test.go): more thorough test cases
Unique-Divine e171a5e
Merge branch 'main' into ud/attonibi
Unique-Divine ec8216f
fix(e2e): avoid BigInt overflow with 10^18 values
Unique-Divine d14ccf3
pull /eth from ud/account-query
Unique-Divine a90ef2f
fix(evmante): CheckSenderBalance needs to use wei
Unique-Divine 82bf5f0
revert: add back NibiruAccount query to mock client
Unique-Divine 9f2fc57
Merge branch 'main' into ud/attonibi
Unique-Divine 6ae937f
fix(e2e-evm): add logging and fix tests
Unique-Divine a6c17b5
chore: resolve last few merge conflicts
Unique-Divine 598b0ce
Merge branch 'main' into ud/attonibi
Unique-Divine 7126a88
refactor: include variable name change suggestion for BalanceNative
Unique-Divine 2c1d2b3
refactor: include variable name change suggestion for BalanceNative
Unique-Divine dfab619
Merge branch 'ud/attonibi' of https://github.com/NibiruChain/nibiru i…
Unique-Divine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { describe, expect, it } from "bun:test"; // eslint-disable-line import/no-unresolved | ||
import { toBigInt, Wallet } from "ethers"; | ||
import { SendNibiCompiled__factory } from "../types/ethers-contracts"; | ||
import { account, provider } from "./setup"; | ||
import { describe, expect, it } from "bun:test" // eslint-disable-line import/no-unresolved | ||
import { toBigInt, Wallet } from "ethers" | ||
import { SendNibiCompiled__factory } from "../types/ethers-contracts" | ||
import { account, provider } from "./setup" | ||
|
||
describe("Send NIBI via smart contract", async () => { | ||
const factory = new SendNibiCompiled__factory(account); | ||
const contract = await factory.deploy(); | ||
const factory = new SendNibiCompiled__factory(account) | ||
const contract = await factory.deploy() | ||
await contract.waitForDeployment() | ||
expect(contract.getAddress()).resolves.toBeDefined() | ||
|
||
it("should send via transfer method", async () => { | ||
const recipient = Wallet.createRandom() | ||
const transferValue = toBigInt(100e6) // NIBI | ||
const transferValue = toBigInt(5e12) * toBigInt(1e6) // 5 micro NIBI | ||
|
||
const ownerBalanceBefore = await provider.getBalance(account) // NIBI | ||
const recipientBalanceBefore = await provider.getBalance(recipient) // NIBI | ||
|
@@ -22,15 +22,25 @@ describe("Send NIBI via smart contract", async () => { | |
}) | ||
const receipt = await tx.wait(1, 5e3) | ||
|
||
expect(provider.getBalance(account)).resolves.toBe( | ||
ownerBalanceBefore - transferValue - receipt.gasUsed, | ||
) | ||
// Assert balances with logging | ||
const tenPow12 = toBigInt(1e12) | ||
const txCostMicronibi = transferValue / tenPow12 + receipt.gasUsed | ||
const txCostWei = txCostMicronibi * tenPow12 | ||
const expectedOwnerWei = ownerBalanceBefore - txCostWei | ||
console.debug("DEBUG should send via transfer method %o:", { | ||
ownerBalanceBefore, | ||
transferValue, | ||
gasUsed: receipt.gasUsed, | ||
gasPrice: `${receipt.gasPrice.toString()} micronibi`, | ||
expectedOwnerWei, | ||
}) | ||
expect(provider.getBalance(account)).resolves.toBe(expectedOwnerWei) | ||
expect(provider.getBalance(recipient)).resolves.toBe(transferValue) | ||
}, 20e3) | ||
|
||
it("should send via send method", async () => { | ||
const recipient = Wallet.createRandom() | ||
const transferValue = toBigInt(100e6) // NIBI | ||
const transferValue = toBigInt(100e12) * toBigInt(1e6) // 100 NIBi | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is equal to |
||
const ownerBalanceBefore = await provider.getBalance(account) // NIBI | ||
const recipientBalanceBefore = await provider.getBalance(recipient) // NIBI | ||
|
@@ -41,15 +51,25 @@ describe("Send NIBI via smart contract", async () => { | |
}) | ||
const receipt = await tx.wait(1, 5e3) | ||
|
||
expect(provider.getBalance(account)).resolves.toBe( | ||
ownerBalanceBefore - transferValue - receipt.gasUsed, | ||
) | ||
// Assert balances with logging | ||
const tenPow12 = toBigInt(1e12) | ||
const txCostMicronibi = transferValue / tenPow12 + receipt.gasUsed | ||
const txCostWei = txCostMicronibi * tenPow12 | ||
const expectedOwnerWei = ownerBalanceBefore - txCostWei | ||
console.debug("DEBUG send via send method %o:", { | ||
ownerBalanceBefore, | ||
transferValue, | ||
gasUsed: receipt.gasUsed, | ||
gasPrice: `${receipt.gasPrice.toString()} micronibi`, | ||
expectedOwnerWei, | ||
}) | ||
expect(provider.getBalance(account)).resolves.toBe(expectedOwnerWei) | ||
expect(provider.getBalance(recipient)).resolves.toBe(transferValue) | ||
}, 20e3) | ||
|
||
it("should send via transfer method", async () => { | ||
const recipient = Wallet.createRandom() | ||
const transferValue = toBigInt(100e6) // NIBI | ||
const transferValue = toBigInt(100e12) * toBigInt(1e6) // 100 NIBI | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is equal to ethers.parseEther("100.0") |
||
const ownerBalanceBefore = await provider.getBalance(account) // NIBI | ||
const recipientBalanceBefore = await provider.getBalance(recipient) // NIBI | ||
|
@@ -60,10 +80,19 @@ describe("Send NIBI via smart contract", async () => { | |
}) | ||
const receipt = await tx.wait(1, 5e3) | ||
|
||
expect(provider.getBalance(account)).resolves.toBe( | ||
ownerBalanceBefore - transferValue - receipt.gasUsed, | ||
) | ||
// Assert balances with logging | ||
const tenPow12 = toBigInt(1e12) | ||
const txCostMicronibi = transferValue / tenPow12 + receipt.gasUsed | ||
const txCostWei = txCostMicronibi * tenPow12 | ||
const expectedOwnerWei = ownerBalanceBefore - txCostWei | ||
console.debug("DEBUG should send via transfer method %o:", { | ||
ownerBalanceBefore, | ||
transferValue, | ||
gasUsed: receipt.gasUsed, | ||
gasPrice: `${receipt.gasPrice.toString()} micronibi`, | ||
expectedOwnerWei, | ||
}) | ||
expect(provider.getBalance(account)).resolves.toBe(expectedOwnerWei) | ||
expect(provider.getBalance(recipient)).resolves.toBe(transferValue) | ||
}, 20e3) | ||
|
||
}) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we better use ether / wei everywhere in JS rather than using
tenPow12
?