-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
41 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,5 @@ | ||
--- | ||
"@deroll/wallet": patch | ||
--- | ||
|
||
fix wallet initialization |
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,47 +1,179 @@ | ||
import { beforeEach, describe, test } from "vitest"; | ||
import { beforeEach, describe, expect, test } from "vitest"; | ||
import { Address, encodePacked, zeroAddress } from "viem"; | ||
|
||
import { | ||
createWallet, | ||
isERC20Deposit, | ||
isEtherDeposit, | ||
parseEtherDeposit, | ||
} from "../src"; | ||
import { erc20PortalAddress, etherPortalAddress } from "../src/rollups"; | ||
|
||
describe("Wallet", () => { | ||
beforeEach(() => {}); | ||
|
||
test("isEtherDeposit", () => { | ||
expect( | ||
isEtherDeposit({ | ||
metadata: { | ||
msg_sender: etherPortalAddress, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}, | ||
payload: "0xdeadbeef", | ||
}), | ||
).toBeTruthy(); | ||
|
||
expect( | ||
isEtherDeposit({ | ||
metadata: { | ||
msg_sender: etherPortalAddress.toLowerCase() as Address, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}, | ||
payload: "0xdeadbeef", | ||
}), | ||
).toBeTruthy(); | ||
|
||
expect( | ||
isEtherDeposit({ | ||
metadata: { | ||
msg_sender: erc20PortalAddress, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}, | ||
payload: "0xdeadbeef", | ||
}), | ||
).toBeFalsy(); | ||
}); | ||
|
||
test("isERC20Deposit", () => { | ||
expect( | ||
isERC20Deposit({ | ||
metadata: { | ||
msg_sender: erc20PortalAddress, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}, | ||
payload: "0xdeadbeef", | ||
}), | ||
).toBeTruthy(); | ||
|
||
expect( | ||
isERC20Deposit({ | ||
metadata: { | ||
msg_sender: erc20PortalAddress.toLowerCase() as Address, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}, | ||
payload: "0xdeadbeef", | ||
}), | ||
).toBeTruthy(); | ||
|
||
expect( | ||
isERC20Deposit({ | ||
metadata: { | ||
msg_sender: etherPortalAddress, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}, | ||
payload: "0xdeadbeef", | ||
}), | ||
).toBeFalsy(); | ||
}); | ||
|
||
test("parseEtherDeposit", () => { | ||
const sender = "0x18930e8a66a1DbE21D00581216789AAB7460Afd0"; | ||
const value = 123456n; | ||
const payload = encodePacked(["address", "uint256"], [sender, value]); | ||
const deposit = parseEtherDeposit(payload); | ||
expect(deposit).toEqual({ | ||
sender, | ||
value, | ||
}); | ||
}); | ||
|
||
test("init", () => {}); | ||
|
||
test("deposit ETH", () => {}); | ||
test("deposit ETH", async () => { | ||
const wallet = createWallet(); | ||
const sender = "0x18930e8a66a1DbE21D00581216789AAB7460Afd0"; | ||
const value = 123456n; | ||
const payload = encodePacked(["address", "uint256"], [sender, value]); | ||
const metadata = { | ||
msg_sender: etherPortalAddress, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}; | ||
const response = await wallet.handler({ metadata, payload }); | ||
expect(response).toEqual("accept"); | ||
expect(wallet.balanceOf(sender)).toEqual(value); | ||
}); | ||
|
||
test("deposit ETH non normalized address", () => {}); | ||
test("deposit ETH non normalized address", async () => { | ||
const wallet = createWallet(); | ||
const sender = "0x18930e8a66a1DbE21D00581216789AAB7460Afd0"; | ||
const value = 123456n; | ||
const payload = encodePacked(["address", "uint256"], [sender, value]); | ||
const metadata = { | ||
msg_sender: etherPortalAddress, | ||
block_number: 0, | ||
epoch_index: 0, | ||
input_index: 0, | ||
timestamp: 0, | ||
}; | ||
const response = await wallet.handler({ metadata, payload }); | ||
expect(response).toEqual("accept"); | ||
expect(wallet.balanceOf(sender.toLowerCase())).toEqual(value); | ||
}); | ||
|
||
test("deposit ERC20", () => {}); | ||
test.todo("deposit ERC20", () => {}); | ||
|
||
test("transfer ETH without balance", () => {}); | ||
test.todo("transfer ETH without balance", () => {}); | ||
|
||
test("transfer ETH", () => {}); | ||
test.todo("transfer ETH", () => {}); | ||
|
||
test("transfer ERC20 without balance", () => {}); | ||
test.todo("transfer ERC20 without balance", () => {}); | ||
|
||
test("transfer ERC20", () => {}); | ||
test.todo("transfer ERC20", () => {}); | ||
|
||
test("withdraw ETH with no balance", () => {}); | ||
test.todo("withdraw ETH with no balance", () => {}); | ||
|
||
test("withdraw ETH with undefined portal address", () => {}); | ||
test.todo("withdraw ETH with undefined portal address", () => {}); | ||
|
||
test("withdraw ETH", () => {}); | ||
test.todo("withdraw ETH", () => {}); | ||
|
||
test("withdraw ERC20", () => {}); | ||
test.todo("withdraw ERC20", () => {}); | ||
|
||
test("withdraw ERC20 with no balance", () => {}); | ||
test.todo("withdraw ERC20 with no balance", () => {}); | ||
|
||
test("depositEtherRoute reject", () => {}); | ||
test.todo("depositEtherRoute reject", () => {}); | ||
|
||
test("depositEtherRoute", () => {}); | ||
test.todo("depositEtherRoute", () => {}); | ||
|
||
test("depositERC20Route reject", () => {}); | ||
test.todo("depositERC20Route reject", () => {}); | ||
|
||
test("depositERC20Route", () => {}); | ||
test.todo("depositERC20Route", () => {}); | ||
|
||
test("withdrawEtherRoute reject no balance", async () => {}); | ||
test.todo("withdrawEtherRoute reject no balance", async () => {}); | ||
|
||
test("withdrawEtherRoute", async () => {}); | ||
test.todo("withdrawEtherRoute", async () => {}); | ||
|
||
test("withdrawERC20Route reject no balance", async () => {}); | ||
test.todo("withdrawERC20Route reject no balance", async () => {}); | ||
|
||
test("withdrawERC20Route", async () => {}); | ||
test.todo("withdrawERC20Route", async () => {}); | ||
}); |
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