Skip to content

Commit

Permalink
fix: make transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Oct 5, 2023
1 parent b85bf43 commit ca021e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:
- name: Run Gear node
run: nohup ./gear --chain ./dev.json --validator --alice --tmp --pruning archive --unsafe-ws-external --unsafe-rpc-external --rpc-methods Unsafe --rpc-cors all &

- name: Sleep
run: sleep 10

- name: Make transfers
run: node ./test/make-transfers.js

Expand Down
46 changes: 20 additions & 26 deletions test/make-transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,29 @@ const main = async () => {
const alice = keyring.addFromUri('//Alice', {}, 'sr25519');
const bob = keyring.addFromUri('//Bob', {}, 'sr25519');

await api.tx.balances
.transferKeepAlive('5HChDnRNd2xn7rGsbJNqJrV5NmpALVKTY9YC2Zzeyu5rjzqC', 1000 * 10 ** 12)
.signAndSend(alice, ({ events }) => {
const transferEvent = events.find(
({ event: { method, section } }) => section === 'system' && method === 'Transfer',
);
const tx = api.tx.utility.batchAll([
api.tx.balances.transferKeepAlive('5HChDnRNd2xn7rGsbJNqJrV5NmpALVKTY9YC2Zzeyu5rjzqC', 1000 * 10 ** 12),
api.tx.balances.transferKeepAlive('5GDCKqWHVg6NG9RQeKQjAQ7t9Pc94UZ3FsxRDCNyesUudi8Y', 100 * 10 ** 12),
]);

if (transferEvent) {
const [from, to, amount] = transferEvent.event.data;
console.log(`${from} transfered ${amount} to ${to}`);
} else {
console.log('No transfer event found');
}
});

await api.tx.balances
.transferKeepAlive('5GDCKqWHVg6NG9RQeKQjAQ7t9Pc94UZ3FsxRDCNyesUudi8Y', 100 * 10 ** 12)
.signAndSend(bob, ({ events }) => {
const transferEvent = events.find(
({ event: { method, section } }) => section === 'system' && method === 'Transfer',
);
await new Promise((resolve, reject) =>
tx.signAndSend(alice, ({ events, status }) => {
if (status.isInBlock) {
const transferEvent = events.find(
({ event: { method, section } }) => section === 'system' && method === 'Transfer',
);

if (transferEvent) {
const [from, to, amount] = transferEvent.event.data;
console.log(`${from} transfered ${amount} to ${to}`);
} else {
console.log('No transfer event found');
if (transferEvent) {
const [from, to, amount] = transferEvent.event.data;
console.log(`${from} transfered ${amount} to ${to}`);
} else {
console.log('No transfer event found');
}
} else if (status.isFinalized) {
resolve('Finalized');
}
});
}),
);
};

main()
Expand Down

0 comments on commit ca021e4

Please sign in to comment.