Skip to content

Commit

Permalink
Add formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CapCap authored and aptos-bot committed Apr 6, 2022
1 parent 112ba66 commit b4abd3d
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 107 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ jobs:
# Run package build+lint + tests
- run: cd ./ecosystem/typescript/sdk && yarn install
- run: cd ./ecosystem/typescript/sdk && yarn lint
- run: cd ./ecosystem/typescript/sdk && yarn fmt:check
- run: cd ./ecosystem/typescript/sdk && yarn test
- run: cd ./ecosystem/typescript/sdk && yarn build

Expand Down
14 changes: 4 additions & 10 deletions ecosystem/typescript/sdk/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ module.exports = {
es2021: true,
node: true,
},
extends: [
"airbnb-base",
],
extends: ["airbnb-base"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: [
"@typescript-eslint",
],
plugins: ["@typescript-eslint"],
rules: {
quotes: ["error", "double"],
"max-len": ["error", 120],
"import/extensions": [
"error",
"never",
],
"import/extensions": ["error", "never"],
"max-classes-per-file": ["error", 10],
"import/prefer-default-export": "off",
"object-curly-newline": "off",
},
settings: {
"import/resolver": {
Expand Down
6 changes: 6 additions & 0 deletions ecosystem/typescript/sdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": false,
"printWidth": 120
}
5 changes: 1 addition & 4 deletions ecosystem/typescript/sdk/examples/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ const FAUCET_URL = process.env.APTOS_FAUCET_URL || "https://faucet.devnet.aptosl
type: "script_function_payload",
function: "0x1::TestCoin::transfer",
type_arguments: [],
arguments: [
account2.address().hex(),
"717",
],
arguments: [account2.address().hex(), "717"],
};
const txnRequest = await client.generateTransaction(account1.address(), payload);
const signedTxn = await client.signTransaction(account1, txnRequest);
Expand Down
18 changes: 5 additions & 13 deletions ecosystem/typescript/sdk/examples/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
AptosClient,
AptosAccount,
FaucetClient,
Types,
} from "aptos";
import { AptosClient, AptosAccount, FaucetClient, Types } from "aptos";

const NODE_URL = process.env.APTOS_NODE_URL || "https://fullnode.devnet.aptoslabs.com";
const FAUCET_URL = process.env.APTOS_FAUCET_URL || "https://faucet.devnet.aptoslabs.com";
Expand All @@ -16,24 +11,21 @@ const FAUCET_URL = process.env.APTOS_FAUCET_URL || "https://faucet.devnet.aptosl
await faucetClient.fundAccount(account1.address(), 5000);
let resources = await client.getAccountResources(account1.address());
let accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
let balance = (accountResource.data as { "coin": { "value": string } }).coin.value;
let balance = (accountResource.data as { coin: { value: string } }).coin.value;
console.log(`account2 coins: ${balance}. Should be 5000!`);

const account2 = new AptosAccount();
await faucetClient.fundAccount(account2.address(), 0);
resources = await client.getAccountResources(account2.address());
accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
balance = (accountResource.data as { "coin": { "value": string } }).coin.value;
balance = (accountResource.data as { coin: { value: string } }).coin.value;
console.log(`account2 coins: ${balance}. Should be 0!`);

const payload: Types.TransactionPayload = {
type: "script_function_payload",
function: "0x1::TestCoin::transfer",
type_arguments: [],
arguments: [
account2.address().hex(),
"717",
],
arguments: [account2.address().hex(), "717"],
};
const txnRequest = await client.generateTransaction(account1.address(), payload);
const signedTxn = await client.signTransaction(account1, txnRequest);
Expand All @@ -42,6 +34,6 @@ const FAUCET_URL = process.env.APTOS_FAUCET_URL || "https://faucet.devnet.aptosl

resources = await client.getAccountResources(account2.address());
accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
balance = (accountResource.data as { "coin": { "value": string } }).coin.value;
balance = (accountResource.data as { coin: { value: string } }).coin.value;
console.log(`account2 coins: ${balance}. Should be 717!`);
})();
4 changes: 4 additions & 0 deletions ecosystem/typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"lint": "eslint \"**/*.ts\"",
"push": "yarn publish --non-interactive --new-version",
"test": "jest",
"_fmt": "prettier --config .prettierrc 'src/**/*.ts' 'examples/**/*.js' 'examples/**/*.ts'",
"fmt": "yarn _fmt --write",
"fmt:check": "yarn _fmt --check",
"cov:clean": "rm -rf coverage"
},
"repository": {
Expand All @@ -37,6 +40,7 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"jest": "^27.5.1",
"prettier": "^2.6.2",
"ts-jest": "^27.1.4",
"ts-loader": "^9.2.8",
"ts-node": "^10.7.0",
Expand Down
14 changes: 7 additions & 7 deletions ecosystem/typescript/sdk/src/aptos_account.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AptosAccount, AptosAccountObject } from "./aptos_account";

const AptosAccountObject: AptosAccountObject = {
"address": "0x978c213990c4833df71548df7ce49d54c759d6b6d932de22b24d56060b7af2aa",
"privateKeyHex": "0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5de19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c",
"publicKeyHex": "0xde19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c",
address: "0x978c213990c4833df71548df7ce49d54c759d6b6d932de22b24d56060b7af2aa",
privateKeyHex:
"0xc5338cd251c22daa8c9c9cc94f498cc8a5c7e1d2e75287a5dda91096fe64efa5de19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c",
publicKeyHex: "0xde19e5d1880cac87d57484ce9ed2e84cf0f9599f12e7cc3a52e4e7657a763f2c",
};


test("generates random accounts", () => {
const a1 = new AptosAccount();
const a2 = new AptosAccount();
Expand Down Expand Up @@ -42,7 +42,7 @@ test("Serializes/Deserializes", () => {

test("Signs Strings", () => {
const a1 = AptosAccount.fromAptosAccountObject(AptosAccountObject);
expect(a1.signHexString("0x77777").hex())
.toBe(
"0xc5de9e40ac00b371cd83b1c197fa5b665b7449b33cd3cdd305bb78222e06a671a49625ab9aea8a039d4bb70e275768084d62b094bc1b31964f2357b7c1af7e0d");
expect(a1.signHexString("0x77777").hex()).toBe(
"0xc5de9e40ac00b371cd83b1c197fa5b665b7449b33cd3cdd305bb78222e06a671a49625ab9aea8a039d4bb70e275768084d62b094bc1b31964f2357b7c1af7e0d",
);
});
6 changes: 3 additions & 3 deletions ecosystem/typescript/sdk/src/aptos_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { HexString, MaybeHexString } from "./hex_string";
import { Types } from "./types";

export interface AptosAccountObject {
address?: string,
publicKeyHex?: Types.HexEncodedBytes,
privateKeyHex: Types.HexEncodedBytes,
address?: string;
publicKeyHex?: Types.HexEncodedBytes;
privateKeyHex: Types.HexEncodedBytes;
}

export class AptosAccount {
Expand Down
19 changes: 8 additions & 11 deletions ecosystem/typescript/sdk/src/aptos_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ test("gets account modules", async () => {
});

test("test raiseForStatus", async () => {
const testData = { "hello": "wow" };
const testData = { hello: "wow" };
const fakeResponse: AxiosResponse = {
status: 200,
statusText: "Status Text",
data: "some string",
request: {
host: "host",
path: "/path"
path: "/path",
},
} as AxiosResponse;

Expand All @@ -49,18 +49,15 @@ test("test raiseForStatus", async () => {

// an error, oh no!
fakeResponse.status = 500;
expect(() => raiseForStatus(200, fakeResponse, testData))
.toThrow("Status Text - \"some string\" @ host/path : {\"hello\":\"wow\"}");
expect(() => raiseForStatus(200, fakeResponse, testData)).toThrow(
'Status Text - "some string" @ host/path : {"hello":"wow"}',
);

expect(() => raiseForStatus(200, fakeResponse))
.toThrow("Status Text - \"some string\" @ host/path");
expect(() => raiseForStatus(200, fakeResponse)).toThrow('Status Text - "some string" @ host/path');

// Just a wild test to make sure it doesn't break: request is `any`!
delete fakeResponse.request;
expect(() => raiseForStatus(200, fakeResponse, testData))
.toThrow("Status Text - \"some string\" : {\"hello\":\"wow\"}");

expect(() => raiseForStatus(200, fakeResponse))
.toThrow("Status Text - \"some string\"");
expect(() => raiseForStatus(200, fakeResponse, testData)).toThrow('Status Text - "some string" : {"hello":"wow"}');

expect(() => raiseForStatus(200, fakeResponse)).toThrow('Status Text - "some string"');
});
98 changes: 47 additions & 51 deletions ecosystem/typescript/sdk/src/faucet_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,50 @@ import { UserTransaction } from "./api/data-contracts";

import { NODE_URL, FAUCET_URL } from "./util.test";


test.skip("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");
let resources = await client.getAccountResources(account1.address());
let accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
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::TestCoin::Balance");
expect((accountResource.data as { "coin": { "value": string } }).coin.value).toBe("0");

const payload: Types.TransactionPayload = {
type: "script_function_payload",
function: "0x1::TestCoin::transfer",
type_arguments: [],
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(account1, signedTxn);
await client.waitForTransaction(transactionRes.hash);

resources = await client.getAccountResources(account2.address());
accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
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;
expect(tx.sender).toBe(account1.address().hex());

const events = await client.getEventsByEventHandle(
tx.sender,
"0x1::TestCoin::TransferEvents",
"sent_events"
);
expect(events[0].type).toBe("0x1::TestCoin::SentEvent");

const events2 = await client.getEventsByEventKey(events[0].key);
expect(events2[0].type).toBe("0x1::TestCoin::SentEvent");
}, 30 * 1000);
test.skip(
"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");
let resources = await client.getAccountResources(account1.address());
let accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
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::TestCoin::Balance");
expect((accountResource.data as { coin: { value: string } }).coin.value).toBe("0");

const payload: Types.TransactionPayload = {
type: "script_function_payload",
function: "0x1::TestCoin::transfer",
type_arguments: [],
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(account1, signedTxn);
await client.waitForTransaction(transactionRes.hash);

resources = await client.getAccountResources(account2.address());
accountResource = resources.find((r) => r.type === "0x1::TestCoin::Balance");
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;
expect(tx.sender).toBe(account1.address().hex());

const events = await client.getEventsByEventHandle(tx.sender, "0x1::TestCoin::TransferEvents", "sent_events");
expect(events[0].type).toBe("0x1::TestCoin::SentEvent");

const events2 = await client.getEventsByEventKey(events[0].key);
expect(events2[0].type).toBe("0x1::TestCoin::SentEvent");
},
30 * 1000,
);
4 changes: 1 addition & 3 deletions ecosystem/typescript/sdk/src/faucet_client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/** Faucet creates and funds accounts. This is a thin wrapper around that. */
import axios from "axios";
import {
AptosClient, AptosClientConfig, raiseForStatus,
} from "./aptos_client";
import { AptosClient, AptosClientConfig, raiseForStatus } from "./aptos_client";
import { Types } from "./types";
import { HexString, MaybeHexString } from "./hex_string";

Expand Down
1 change: 0 additions & 1 deletion ecosystem/typescript/sdk/src/hex_string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function validate(hexString: HexString) {
expect(hexString.noPrefix()).toBe(withoutPrefix);
}


test("from/to buffer", () => {
const hs = new HexString(withPrefix);
expect(hs.toBuffer().toString("hex")).toBe(withoutPrefix);
Expand Down
6 changes: 2 additions & 4 deletions ecosystem/typescript/sdk/src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const NODE_URL =
process.env.APTOS_NODE_URL || "https://fullnode.devnet.aptoslabs.com";
export const FAUCET_URL =
process.env.APTOS_FAUCET_URL || "https://faucet.devnet.aptoslabs.com";
export const NODE_URL = process.env.APTOS_NODE_URL || "https://fullnode.devnet.aptoslabs.com";
export const FAUCET_URL = process.env.APTOS_FAUCET_URL || "https://faucet.devnet.aptoslabs.com";

test("noop", () => {
// All TS files are compiled by default into the npm package
Expand Down

0 comments on commit b4abd3d

Please sign in to comment.