forked from elizaOS/eliza
-
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.
fix: transfer action fix elizaOS#735
- Loading branch information
Showing
3 changed files
with
77 additions
and
34 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
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,55 @@ | ||
import { describe, it, expect, beforeEach } from "vitest"; | ||
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; | ||
import { Account, Chain } from "viem"; | ||
|
||
import { TransferAction } from "../actions/transfer"; | ||
import { WalletProvider } from "../providers/wallet"; | ||
|
||
describe("Transfer Action", () => { | ||
let wp: WalletProvider; | ||
|
||
beforeEach(async () => { | ||
const pk = generatePrivateKey(); | ||
const customChains = prepareChains(); | ||
wp = new WalletProvider(pk, customChains); | ||
}); | ||
describe("Constructor", () => { | ||
it("should initialize with wallet provider", () => { | ||
const ta = new TransferAction(wp); | ||
|
||
expect(ta).to.toBeDefined(); | ||
}); | ||
}); | ||
describe("Transfer", () => { | ||
let ta: TransferAction; | ||
let receiver: Account; | ||
|
||
beforeEach(() => { | ||
ta = new TransferAction(wp); | ||
receiver = privateKeyToAccount(generatePrivateKey()); | ||
}); | ||
|
||
it("throws if not enough gas", async () => { | ||
await expect( | ||
ta.transfer({ | ||
fromChain: "iotexTestnet", | ||
toAddress: receiver.address, | ||
amount: "1", | ||
}) | ||
).rejects.toThrow( | ||
"Transfer failed: The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account." | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
const prepareChains = () => { | ||
let customChains: Record<string, Chain> = {}; | ||
const chainNames = ["iotexTestnet"]; | ||
chainNames.forEach( | ||
(chain) => | ||
(customChains[chain] = WalletProvider.genChainFromName(chain)) | ||
); | ||
|
||
return customChains; | ||
}; |