stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
93 lines (92 loc) • 5.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const stellar_sdk_1 = require("@stellar/stellar-sdk");
const account_1 = require("../../../stellar-plus/account");
const base_1 = require("../../../stellar-plus/account/base");
const network_1 = require("../../../stellar-plus/network");
const stellar_test_ledger_1 = require("../../../stellar-plus/test/stellar-test-ledger");
const unsignedTransactionXdr = 'AAAAAgAAAABgo53xrTeR7T9m6iwXaLPmnEoWIiVB8KW/GNmxB10yugAAAGQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
describe('Managing Account Use Case: ', () => {
const logLevel = 'TRACE';
const stellarTestLedger = new stellar_test_ledger_1.StellarTestLedger({
logLevel,
network: stellar_test_ledger_1.TestLedgerNetwork.LOCAL,
containerImageVersion: stellar_test_ledger_1.SupportedImageVersions.LASTEST,
});
let networkConfig;
beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const container = yield stellarTestLedger.start();
expect(container).toBeDefined();
networkConfig = (0, network_1.CustomNet)(yield stellarTestLedger.getNetworkConfiguration());
expect(networkConfig.horizonUrl).toBeDefined();
expect(networkConfig.networkPassphrase).toBeDefined();
expect(networkConfig.rpcUrl).toBeDefined();
expect(networkConfig.friendbotUrl).toBeDefined();
}));
afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield stellarTestLedger.stop();
yield stellarTestLedger.destroy();
}));
describe('A DefaultAccountHandler', () => {
let accountDef;
beforeAll(() => {
accountDef = new account_1.DefaultAccountHandler({ networkConfig });
});
describe('Given a fresh account', () => {
it('should initialize the account with Friendbot', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield expect(accountDef.initializeWithFriendbot()).toResolve();
}));
});
describe('Given an initialized account', () => {
it('should fail when attempting to initialize the account with Friendbot again', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield expect(accountDef.initializeWithFriendbot()).rejects.toThrow();
}));
it('should be able to fetch balances for the initialize account', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _a;
const balances = yield accountDef.getBalances();
const xlmBalance = (_a = balances.find((bal) => bal.asset_type === 'native')) === null || _a === void 0 ? void 0 : _a.balance;
expect(balances).toBeDefined();
expect(balances.length).toBeGreaterThan(0);
expect(xlmBalance).toBe('10000.0000000');
}));
it('should be able to sign a transaction with the accoutns private key', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const transaction = stellar_sdk_1.TransactionBuilder.fromXDR(unsignedTransactionXdr, networkConfig.networkPassphrase);
const signedTransaction = yield accountDef.sign(transaction);
const signedEnvelope = stellar_sdk_1.TransactionBuilder.fromXDR(signedTransaction, networkConfig.networkPassphrase);
expect(signedTransaction).toBeDefined();
expect(signedEnvelope).toBeDefined();
expect(signedEnvelope.signatures.length).toBeGreaterThan(0);
}));
});
});
describe('An AccountBase', () => {
let accountBase;
beforeAll(() => {
const randomPublicKey = stellar_sdk_1.Keypair.random().publicKey();
accountBase = new base_1.AccountBase({
networkConfig,
publicKey: randomPublicKey,
});
});
describe('Given a fresh account', () => {
it('should initialize the account with Friendbot', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield expect(accountBase.initializeWithFriendbot()).toResolve();
}));
});
describe('Given an initialized account', () => {
it('should fail when attempting to initialize the account with Friendbot again', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield expect(accountBase.initializeWithFriendbot()).rejects.toThrow();
}));
it('should be able to fetch balances for the initialize account', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _a;
const balances = yield accountBase.getBalances();
const xlmBalance = (_a = balances.find((bal) => bal.asset_type === 'native')) === null || _a === void 0 ? void 0 : _a.balance;
expect(balances).toBeDefined();
expect(balances.length).toBeGreaterThan(0);
expect(xlmBalance).toBe('10000.0000000');
}));
});
});
});