-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add docs for creating a wallet-strategy
- Loading branch information
1 parent
7b50184
commit 790bff5
Showing
6 changed files
with
194 additions
and
8 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
109 changes: 109 additions & 0 deletions
109
packages/wallets/wallet-core/src/broadcaster/MsgBroadcaster.spec.ts
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,109 @@ | ||
import { Network } from '@injectivelabs/networks' | ||
import { MsgBroadcaster } from './MsgBroadcaster' | ||
import { MsgBroadcasterOptions } from './types' | ||
import { | ||
Wallet, | ||
WalletStrategyArguments, | ||
ConcreteEthereumWalletStrategyArgs, | ||
} from '@injectivelabs/wallet-base' | ||
import { EthereumChainId } from '@injectivelabs/ts-types' | ||
import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key' | ||
|
||
const strategyArgs: WalletStrategyArguments = {} /** define the args */ | ||
const strategyEthArgs: ConcreteEthereumWalletStrategyArgs = | ||
{} /** if the wallet is an Ethereum wallet */ | ||
const strategies = { | ||
[Wallet.PrivateKey]: new PrivateKeyWalletStrategy(strategyEthArgs), | ||
} | ||
|
||
export const walletStrategy = new BaseWalletStrategy({ | ||
...strategyArgs, | ||
strategies, | ||
}) | ||
|
||
const broadcasterArgs: MsgBroadcasterOptions = | ||
{} /** define the broadcaster args */ | ||
export const msgBroadcaster = new MsgBroadcaster({ | ||
...broadcasterArgs, | ||
walletStrategy, | ||
}) | ||
|
||
describe('MsgBroadcaster', () => { | ||
test('prepares, simulates, signs and broadcasts a transaction', async () => { | ||
const privateKey = PrivateKey.fromHex( | ||
process.env.TEST_PRIVATE_KEY as string, | ||
) | ||
|
||
const network = Network.Devnet | ||
const injectiveAddress = privateKey.toBech32() | ||
|
||
const message = MsgSend.fromJSON({ | ||
srcInjectiveAddress: injectiveAddress, | ||
dstInjectiveAddress: injectiveAddress, | ||
amount: { | ||
amount: '1', | ||
denom: 'inj', | ||
}, | ||
}) | ||
|
||
const response = await new MsgBroadcasterWithPk({ | ||
network, | ||
privateKey, | ||
simulateTx: true, | ||
}).broadcast({ msgs: message }) | ||
|
||
expect(response.txHash).toBeDefined() | ||
}, 60000) | ||
|
||
test.skip('prepares, simulates, signs and broadcasts a transaction with fee delegation', async () => { | ||
const privateKey = PrivateKey.fromHex( | ||
process.env.TEST_PRIVATE_KEY as string, | ||
) | ||
|
||
const network = Network.Devnet | ||
const injectiveAddress = privateKey.toBech32() | ||
|
||
const message = MsgSend.fromJSON({ | ||
srcInjectiveAddress: injectiveAddress, | ||
dstInjectiveAddress: injectiveAddress, | ||
amount: { | ||
amount: '1', | ||
denom: 'inj', | ||
}, | ||
}) | ||
|
||
const response = await new MsgBroadcasterWithPk({ | ||
network, | ||
privateKey, | ||
simulateTx: true, | ||
ethereumChainId: EthereumChainId.Sepolia, | ||
}).broadcastWithFeeDelegation({ msgs: message }) | ||
|
||
expect(response.txHash).toBeDefined() | ||
}, 60000) | ||
|
||
test.skip('simulates a transaction', async () => { | ||
const privateKey = PrivateKey.fromHex( | ||
process.env.TEST_PRIVATE_KEY as string, | ||
) | ||
|
||
const network = Network.Devnet | ||
const injectiveAddress = privateKey.toBech32() | ||
|
||
const message = MsgSend.fromJSON({ | ||
srcInjectiveAddress: injectiveAddress, | ||
dstInjectiveAddress: injectiveAddress, | ||
amount: { | ||
amount: '1', | ||
denom: 'inj', | ||
}, | ||
}) | ||
|
||
const response = await new MsgBroadcasterWithPk({ | ||
network, | ||
privateKey, | ||
}).simulate({ msgs: message }) | ||
|
||
expect(response.result).toBeDefined() | ||
}, 60000) | ||
}) |
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
53 changes: 53 additions & 0 deletions
53
packages/wallets/wallet-private-key/src/strategy/strategy.spec.ts
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,53 @@ | ||
import { Network } from '@injectivelabs/networks' | ||
import { | ||
MsgBroadcaster, | ||
BaseWalletStrategy, | ||
MsgBroadcasterOptions, | ||
} from '@injectivelabs/wallet-core' | ||
import { Wallet, WalletStrategyArguments } from '@injectivelabs/wallet-base' | ||
import { MsgSend, PrivateKey } from '@injectivelabs/sdk-ts' | ||
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types' | ||
import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key' | ||
|
||
const strategyArgs: WalletStrategyArguments = { | ||
chainId: ChainId.Devnet, | ||
wallet: Wallet.PrivateKey, | ||
strategies: { | ||
[Wallet.PrivateKey]: new PrivateKeyWalletStrategy({ | ||
chainId: ChainId.Devnet, | ||
ethereumOptions: { | ||
ethereumChainId: EthereumChainId.Sepolia, | ||
rpcUrl: '', | ||
}, | ||
privateKey: process.env.TEST_PRIVATE_KEY as string, | ||
}), | ||
}, | ||
} | ||
const walletStrategy = new BaseWalletStrategy(strategyArgs) | ||
|
||
const broadcasterArgs: MsgBroadcasterOptions = { | ||
walletStrategy, | ||
simulateTx: true, | ||
network: Network.Devnet, | ||
} | ||
const msgBroadcaster = new MsgBroadcaster(broadcasterArgs) | ||
|
||
describe('MsgBroadcaster', () => { | ||
test('prepares, simulates, signs and broadcasts a transaction', async () => { | ||
const pk = PrivateKey.fromHex(process.env.TEST_PRIVATE_KEY as string) | ||
const injectiveAddress = pk.toBech32() | ||
|
||
const message = MsgSend.fromJSON({ | ||
srcInjectiveAddress: injectiveAddress, | ||
dstInjectiveAddress: injectiveAddress, | ||
amount: { | ||
amount: '1', | ||
denom: 'inj', | ||
}, | ||
}) | ||
|
||
const response = await msgBroadcaster.broadcast({ msgs: message }) | ||
|
||
expect(response.txHash).toBeDefined() | ||
}, 60000) | ||
}) |
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