forked from sei-protocol/sei-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EVM] Merge balances on associate tx (sei-protocol#1630)
* add associate tx test * fix migration of balances * fix getAdmin function * add log so we can debug key import on github actions * fix test (multi-interaction cli step)
- Loading branch information
1 parent
502a560
commit 22404d5
Showing
7 changed files
with
212 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const { fundAddress, fundSeiAddress, getSeiBalance, associateKey, importKey, waitForReceipt, bankSend, evmSend, getNativeAccount} = require("./lib"); | ||
const { expect } = require("chai"); | ||
|
||
describe("Associate Balances", function () { | ||
|
||
const keys = { | ||
"test1": { | ||
seiAddress: 'sei1nzdg7e6rvkrmvp5zzmp5tupuj0088nqsa4mze4', | ||
evmAddress: '0x90684e7F229f2d8E2336661f79caB693E4228Ff7' | ||
}, | ||
"test2": { | ||
seiAddress: 'sei1jqgph9jpdtvv64e3rzegxtssvgmh7lxnn8vmdq', | ||
evmAddress: '0x28b2B0621f76A2D08A9e04acb7F445E61ba5b7E7' | ||
}, | ||
"test3": { | ||
seiAddress: 'sei1qkawqt7dw09rkvn53lm2deamtfcpuq9v0h6zur', | ||
evmAddress: '0xCb2FB25A6a34Ca874171Ac0406d05A49BC45a1cF' | ||
} | ||
} | ||
|
||
const addresses = { | ||
seiAddress: 'sei1nzdg7e6rvkrmvp5zzmp5tupuj0088nqsa4mze4', | ||
evmAddress: '0x90684e7F229f2d8E2336661f79caB693E4228Ff7' | ||
} | ||
|
||
function truncate(num, byThisManyDecimals) { | ||
return parseFloat(`${num}`.slice(0, 12)) | ||
} | ||
|
||
async function verifyAssociation(seiAddr, evmAddr, associateFunc) { | ||
const beforeSei = BigInt(await getSeiBalance(seiAddr)) | ||
const beforeEvm = await ethers.provider.getBalance(evmAddr) | ||
const gas = await associateFunc(seiAddr) | ||
const afterSei = BigInt(await getSeiBalance(seiAddr)) | ||
const afterEvm = await ethers.provider.getBalance(evmAddr) | ||
|
||
// console.log(`SEI Balance (before): ${beforeSei}`) | ||
// console.log(`EVM Balance (before): ${beforeEvm}`) | ||
// console.log(`SEI Balance (after): ${afterSei}`) | ||
// console.log(`EVM Balance (after): ${afterEvm}`) | ||
|
||
const multiplier = BigInt(1000000000000) | ||
expect(afterEvm).to.equal((beforeSei * multiplier) + beforeEvm - (gas * multiplier)) | ||
expect(afterSei).to.equal(truncate(beforeSei - gas)) | ||
} | ||
|
||
before(async function(){ | ||
await importKey("test1", "../contracts/test/test1.key") | ||
await importKey("test2", "../contracts/test/test2.key") | ||
await importKey("test3", "../contracts/test/test3.key") | ||
}) | ||
|
||
it("should associate with sei transaction", async function(){ | ||
const addr = keys.test1 | ||
await fundSeiAddress(addr.seiAddress, "10000000000") | ||
await fundAddress(addr.evmAddress, "200"); | ||
|
||
await verifyAssociation(addr.seiAddress, addr.evmAddress, async function(){ | ||
await bankSend(addr.seiAddress, "test1") | ||
return BigInt(20000) | ||
}) | ||
}); | ||
|
||
it("should associate with evm transaction", async function(){ | ||
const addr = keys.test2 | ||
await fundSeiAddress(addr.seiAddress, "10000000000") | ||
await fundAddress(addr.evmAddress, "200"); | ||
|
||
await verifyAssociation(addr.seiAddress, addr.evmAddress, async function(){ | ||
const txHash = await evmSend(addr.evmAddress, "test2", "0") | ||
const receipt = await waitForReceipt(txHash) | ||
return BigInt(receipt.gasUsed * (receipt.gasPrice / BigInt(1000000000000))) | ||
}) | ||
}); | ||
|
||
it("should associate with associate transaction", async function(){ | ||
const addr = keys.test3 | ||
await fundSeiAddress(addr.seiAddress, "10000000000") | ||
await fundAddress(addr.evmAddress, "200"); | ||
|
||
await verifyAssociation(addr.seiAddress, addr.evmAddress, async function(){ | ||
await associateKey("test3") | ||
return BigInt(0) | ||
}) | ||
}); | ||
|
||
}) |
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,9 @@ | ||
-----BEGIN TENDERMINT PRIVATE KEY----- | ||
kdf: bcrypt | ||
salt: 377151BDAA4DCDD8761F9489519D3E90 | ||
type: secp256k1 | ||
|
||
aMtUz1ow5FBmictYj67Wm5qJksJsiF0O86PrjOHnoINVBn0aCzYNxdkvNg0PP0Qb | ||
jHfcKaDPgk3PaeW16YqNJwveVX71A7lwpUmfT44= | ||
=46/d | ||
-----END TENDERMINT PRIVATE KEY----- |
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,9 @@ | ||
-----BEGIN TENDERMINT PRIVATE KEY----- | ||
kdf: bcrypt | ||
salt: 72E32FD4A4089E256F1EFCCBBA576592 | ||
type: secp256k1 | ||
|
||
MZ77pmO6izHdpkKVWYhGLGjZUAhf//WGURYVqUqhjJbCGtAXEkFKrjEAEpO3pyn1 | ||
tYe8Hlry3BiqLoLY+j7CwE7W6g3WshJouXCrUiY= | ||
=VWqu | ||
-----END TENDERMINT PRIVATE KEY----- |
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,9 @@ | ||
-----BEGIN TENDERMINT PRIVATE KEY----- | ||
kdf: bcrypt | ||
salt: CDAEDE2709FFE1049C3E217BCD179BB2 | ||
type: secp256k1 | ||
|
||
l8hOkMcbc9ugxiUmS3k1wdziq6N+qhas25H0fjWD9tDK/BPn0QkY3pIz39TZJNuf | ||
/l9ImHhYxccWPoyTybKmXEjMaKLpFRZLdu+t844= | ||
=lvXk | ||
-----END TENDERMINT PRIVATE KEY----- |
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