-
Notifications
You must be signed in to change notification settings - Fork 15
feat: partial tx facade #408
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fae1ef2
feat: addSend with optional utxos argument
r4mmer e1949a1
feat: calculate balance method
r4mmer 547f28b
feat: calculate authority balance
r4mmer b41b114
fix: utxo selection
r4mmer a0d6423
fix: use base58 address
r4mmer 1c180f0
tests: PartialTxProposal tests
r4mmer 4be9aeb
tests: more partialTx proposal tests
r4mmer 63d1b15
chore: increase code coverage
r4mmer 34f4686
chore: change coverage
r4mmer a3d831b
feat: filter utxos
r4mmer 8693816
feat: addressPath helper
r4mmer 8c0caae
chore: use addressIndex to get addressPath
r4mmer ce01429
feat: expose bufferUtils
r4mmer 88bb352
feat: track token authority with authorities property
r4mmer dc9530a
chore: add authorities to constructor
r4mmer 92e2a33
tests: remove tokenData from partial tx constructor
r4mmer d2aa086
tests: remove tokenData from expected tests
r4mmer 94cff9e
tests: change mock variables
r4mmer 0c5eff3
tests: fix mock methods
r4mmer f821ef7
tests: integration tests
r4mmer 0496a1c
tests: expect serialized string
r4mmer a85d068
tests: missing declaration
r4mmer 99947e1
tests: remove expect
r4mmer b504c85
tests: setStore before signing
r4mmer 0e2f16d
chore: use constants
r4mmer d3f1133
tests(integration): add balance check for atomic-swap
r4mmer 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 hidden or 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,82 @@ | ||
import { GenesisWalletHelper } from './helpers/genesis-wallet.helper'; | ||
import { | ||
createTokenHelper, | ||
DEFAULT_PIN_CODE, | ||
generateWalletHelper, | ||
stopAllWallets, | ||
waitForTxReceived, | ||
} from './helpers/wallet.helper'; | ||
import { HATHOR_TOKEN_CONFIG } from '../../src/constants'; | ||
import SendTransaction from '../../src/new/sendTransaction'; | ||
import PartialTxProposal from '../../src/wallet/partialTxProposal'; | ||
import storage from '../../src/storage'; | ||
|
||
describe('partial tx proposal', () => { | ||
afterEach(async () => { | ||
await stopAllWallets(); | ||
await GenesisWalletHelper.clearListeners(); | ||
}); | ||
|
||
it('Should exchange tokens between wallets', async () => { | ||
// Create the wallet | ||
const hWallet1 = await generateWalletHelper(); | ||
const hWallet2 = await generateWalletHelper(); | ||
const network = hWallet1.getNetworkObject(); | ||
|
||
// Injecting funds and creating a new custom token | ||
await GenesisWalletHelper.injectFunds(hWallet1.getAddressAtIndex(0), 101); | ||
const { hash: token1Uid } = await createTokenHelper( | ||
hWallet1, | ||
'Token1', | ||
'TK1', | ||
100, | ||
); | ||
|
||
// Injecting funds and creating a new custom token | ||
await GenesisWalletHelper.injectFunds(hWallet2.getAddressAtIndex(0), 10); | ||
const { hash: token2Uid } = await createTokenHelper( | ||
hWallet2, | ||
'Token2', | ||
'TK2', | ||
1000, | ||
); | ||
|
||
/** | ||
* The exchange will be: | ||
* | ||
* Wallet1 will send 100 HTR and 100 TK1 | ||
* Wallet2 will send 1000 TK2 | ||
*/ | ||
const proposal = new PartialTxProposal(network); | ||
// Wallet1 side | ||
proposal.addSend(hWallet1, HATHOR_TOKEN_CONFIG.uid, 100); | ||
proposal.addSend(hWallet1, token1Uid, 100); | ||
proposal.addReceive(hWallet1, token2Uid, 1000); | ||
expect(proposal.partialTx.isComplete()).toBeFalsy(); | ||
// Wallet2 side | ||
proposal.addSend(hWallet2, token2Uid, 1000); | ||
proposal.addReceive(hWallet2, HATHOR_TOKEN_CONFIG.uid, 100); | ||
proposal.addReceive(hWallet2, token1Uid, 100); | ||
expect(proposal.partialTx.isComplete()).toBeTruthy(); | ||
|
||
const serialized = proposal.partialTx.serialize(); | ||
const proposal1 = PartialTxProposal.fromPartialTx(serialized, network); | ||
storage.setStore(hWallet1.store); | ||
await proposal1.signData(DEFAULT_PIN_CODE, true); | ||
expect(proposal1.signatures.isComplete()).toBeFalsy(); | ||
|
||
const proposal2 = PartialTxProposal.fromPartialTx(serialized, network); | ||
storage.setStore(hWallet2.store); | ||
await proposal2.signData(DEFAULT_PIN_CODE, true); | ||
|
||
expect(proposal2.signatures.isComplete()).toBeFalsy(); | ||
|
||
proposal2.signatures.addSignatures(proposal1.signatures.serialize()); | ||
expect(proposal2.signatures.isComplete()).toBeTruthy(); | ||
|
||
const transaction = proposal2.prepareTx(); | ||
const sendTransaction = new SendTransaction({ transaction, network }); | ||
const tx = await sendTransaction.runFromMining(); | ||
expect(tx.hash).toBeDefined(); | ||
tuliomir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.