forked from aptos-labs/aptos-core
-
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.
[sdk][typescript] Fix more styling issues
- Loading branch information
Showing
8 changed files
with
149 additions
and
143 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 @@ | ||
src/api/* |
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,48 +1,50 @@ | ||
import { AptosAccount, AptosAccountObject } from "./aptos_account"; | ||
import { AptosAccount, AptosAccountObject } from './aptos_account'; | ||
|
||
const AptosAccountObject: AptosAccountObject = { | ||
address: "0x978c213990c4833df71548df7ce49d54c759d6b6d932de22b24d56060b7af2aa", | ||
const aptosAccountObject: AptosAccountObject = { | ||
address: '0x978c213990c4833df71548df7ce49d54c759d6b6d932de22b24d56060b7af2aa', | ||
privateKeyHex: | ||
"0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5de19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c", | ||
publicKeyHex: "0xde19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c", | ||
// eslint-disable-next-line max-len | ||
'0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5de19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c', | ||
publicKeyHex: '0xde19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c', | ||
}; | ||
|
||
test("generates random accounts", () => { | ||
test('generates random accounts', () => { | ||
const a1 = new AptosAccount(); | ||
const a2 = new AptosAccount(); | ||
expect(a1.authKey()).not.toBe(a2.authKey()); | ||
expect(a1.address().hex()).not.toBe(a2.address().hex()); | ||
}); | ||
|
||
test("accepts custom address", () => { | ||
const address = "0x777"; | ||
test('accepts custom address', () => { | ||
const address = '0x777'; | ||
const a1 = new AptosAccount(null, address); | ||
expect(a1.address().hex()).toBe(address); | ||
}); | ||
|
||
test("Deserializes from AptosAccountObject", () => { | ||
const a1 = AptosAccount.fromAptosAccountObject(AptosAccountObject); | ||
expect(a1.address().hex()).toBe(AptosAccountObject.address); | ||
expect(a1.pubKey().hex()).toBe(AptosAccountObject.publicKeyHex); | ||
test('Deserializes from AptosAccountObject', () => { | ||
const a1 = AptosAccount.fromAptosAccountObject(aptosAccountObject); | ||
expect(a1.address().hex()).toBe(aptosAccountObject.address); | ||
expect(a1.pubKey().hex()).toBe(aptosAccountObject.publicKeyHex); | ||
}); | ||
|
||
test("Deserializes from AptosAccountObject without address", () => { | ||
const privateKeyObject = { privateKeyHex: AptosAccountObject.privateKeyHex }; | ||
test('Deserializes from AptosAccountObject without address', () => { | ||
const privateKeyObject = { privateKeyHex: aptosAccountObject.privateKeyHex }; | ||
const a1 = AptosAccount.fromAptosAccountObject(privateKeyObject); | ||
expect(a1.address().hex()).toBe(AptosAccountObject.address); | ||
expect(a1.pubKey().hex()).toBe(AptosAccountObject.publicKeyHex); | ||
expect(a1.address().hex()).toBe(aptosAccountObject.address); | ||
expect(a1.pubKey().hex()).toBe(aptosAccountObject.publicKeyHex); | ||
}); | ||
|
||
test("Serializes/Deserializes", () => { | ||
test('Serializes/Deserializes', () => { | ||
const a1 = new AptosAccount(); | ||
const a2 = AptosAccount.fromAptosAccountObject(a1.toPrivateKeyObject()); | ||
expect(a1.authKey().hex()).toBe(a2.authKey().hex()); | ||
expect(a1.address().hex()).toBe(a2.address().hex()); | ||
}); | ||
|
||
test("Signs Strings", () => { | ||
const a1 = AptosAccount.fromAptosAccountObject(AptosAccountObject); | ||
expect(a1.signHexString("0x77777").hex()).toBe( | ||
"0xc5de9e40ac00b371cd83b1c197fa5b665b7449b33cd3cdd305bb78222e06a671a49625ab9aea8a039d4bb70e275768084d62b094bc1b31964f2357b7c1af7e0d", | ||
test('Signs Strings', () => { | ||
const a1 = AptosAccount.fromAptosAccountObject(aptosAccountObject); | ||
expect(a1.signHexString('0x77777').hex()).toBe( | ||
// eslint-disable-next-line max-len | ||
'0xc5de9e40ac00b371cd83b1c197fa5b665b7449b33cd3cdd305bb78222e06a671a49625ab9aea8a039d4bb70e275768084d62b094bc1b31964f2357b7c1af7e0d', | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,68 +1,68 @@ | ||
import { AptosClient } from "./aptos_client"; | ||
import { FaucetClient } from "./faucet_client"; | ||
import { AptosAccount } from "./aptos_account"; | ||
import { Types } from "./types"; | ||
import { UserTransaction } from "./api/data-contracts"; | ||
import { HexString } from "./hex_string"; | ||
import { AptosClient } from './aptos_client'; | ||
import { FaucetClient } from './faucet_client'; | ||
import { AptosAccount } from './aptos_account'; | ||
import { Types } from './types'; | ||
import { UserTransaction } from './api/data-contracts'; | ||
import { HexString } from './hex_string'; | ||
|
||
import { NODE_URL, FAUCET_URL } from "./util.test"; | ||
import { NODE_URL, FAUCET_URL } from './util.test'; | ||
|
||
test( | ||
"full tutorial faucet flow", | ||
'full tutorial faucet flow', | ||
async () => { | ||
const client = new AptosClient(NODE_URL); | ||
const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL); | ||
|
||
const account1 = new AptosAccount(); | ||
const txns = await faucetClient.fundAccount(account1.address(), 5000); | ||
const tx1 = await client.getTransaction(txns[1]); | ||
expect(tx1.type).toBe("user_transaction"); | ||
expect(tx1.type).toBe('user_transaction'); | ||
let resources = await client.getAccountResources(account1.address()); | ||
let accountResource = resources.find((r) => r.type === "0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>"); | ||
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe("5000"); | ||
let accountResource = resources.find((r) => r.type === '0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>'); | ||
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe('5000'); | ||
|
||
const account2 = new AptosAccount(); | ||
await faucetClient.fundAccount(account2.address(), 0); | ||
resources = await client.getAccountResources(account2.address()); | ||
accountResource = resources.find((r) => r.type === "0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>"); | ||
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe("0"); | ||
accountResource = resources.find((r) => r.type === '0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>'); | ||
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe('0'); | ||
|
||
const payload: Types.TransactionPayload = { | ||
type: "script_function_payload", | ||
function: "0x1::Coin::transfer", | ||
type_arguments: ["0x1::TestCoin::TestCoin"], | ||
arguments: [account2.address().hex(), "717"], | ||
type: 'script_function_payload', | ||
function: '0x1::Coin::transfer', | ||
type_arguments: ['0x1::TestCoin::TestCoin'], | ||
arguments: [account2.address().hex(), '717'], | ||
}; | ||
const txnRequest = await client.generateTransaction(account1.address(), payload); | ||
const signedTxn = await client.signTransaction(account1, txnRequest); | ||
const transactionRes = await client.submitTransaction(signedTxn); | ||
await client.waitForTransaction(transactionRes.hash); | ||
|
||
resources = await client.getAccountResources(account2.address()); | ||
accountResource = resources.find((r) => r.type === "0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>"); | ||
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe("717"); | ||
accountResource = resources.find((r) => r.type === '0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>'); | ||
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe('717'); | ||
|
||
const res = await client.getAccountTransactions(account1.address(), { start: 0 }); | ||
const tx = res.find((e) => e.type === "user_transaction") as UserTransaction; | ||
const tx = res.find((e) => e.type === 'user_transaction') as UserTransaction; | ||
expect(new HexString(tx.sender).toShortString()).toBe(account1.address().toShortString()); | ||
|
||
const events = await client.getEventsByEventHandle( | ||
tx.sender, | ||
"0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>", | ||
"withdraw_events", | ||
'0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>', | ||
'withdraw_events', | ||
); | ||
expect(events[0].type).toBe("0x1::Coin::WithdrawEvent"); | ||
expect(events[0].type).toBe('0x1::Coin::WithdrawEvent'); | ||
|
||
const event_subset = await client.getEventsByEventHandle( | ||
const eventSubset = await client.getEventsByEventHandle( | ||
tx.sender, | ||
"0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>", | ||
"withdraw_events", | ||
'0x1::Coin::CoinStore<0x1::TestCoin::TestCoin>', | ||
'withdraw_events', | ||
{ start: 0, limit: 1 }, | ||
); | ||
expect(event_subset[0].type).toBe("0x1::Coin::WithdrawEvent"); | ||
expect(eventSubset[0].type).toBe('0x1::Coin::WithdrawEvent'); | ||
|
||
const events2 = await client.getEventsByEventKey(events[0].key); | ||
expect(events2[0].type).toBe("0x1::Coin::WithdrawEvent"); | ||
expect(events2[0].type).toBe('0x1::Coin::WithdrawEvent'); | ||
}, | ||
30 * 1000, | ||
); |
Oops, something went wrong.