feat: returning wallet address from warp.testing.generateWallet
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import fs from 'fs';
|
||||
|
||||
import ArLocal from 'arlocal';
|
||||
import Arweave from 'arweave';
|
||||
import { JWKInterface } from 'arweave/node/lib/wallet';
|
||||
import path from 'path';
|
||||
import { mineBlock } from '../_helpers';
|
||||
@@ -30,8 +29,7 @@ describe('Testing the Warp client', () => {
|
||||
|
||||
warp = WarpFactory.forLocal(1800);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
|
||||
({ jwk: wallet } = await warp.testing.generateWallet());
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/very-complicated-contract.js'), 'utf8');
|
||||
|
||||
// deploying contract using the new SDK.
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Testing the Warp client', () => {
|
||||
|
||||
LoggerFactory.INST.logLevel('error');
|
||||
warp = WarpFactory.forLocal(1810);
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet());
|
||||
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/example-contract.js'), 'utf8');
|
||||
initialState = fs.readFileSync(path.join(__dirname, '../data/example-contract-state.json'), 'utf8');
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('Testing the Warp client', () => {
|
||||
|
||||
LoggerFactory.INST.logLevel('error');
|
||||
warp = WarpFactory.forLocal(1830);
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/inf-loop-contract.js'), 'utf8');
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
warp = WarpFactory.forLocal(1820);
|
||||
|
||||
({ arweave } = warp);
|
||||
wallet = await warp.testing.generateWallet();
|
||||
walletAddress = await arweave.wallets.jwkToAddress(wallet);
|
||||
({ jwk: wallet, address: walletAddress } = await warp.testing.generateWallet());
|
||||
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/token-pst.js'), 'utf8');
|
||||
const stateFromFile: PstState = JSON.parse(fs.readFileSync(path.join(__dirname, '../data/token-pst.json'), 'utf8'));
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('Testing the Warp client', () => {
|
||||
LoggerFactory.INST.logLevel('error');
|
||||
warp = WarpFactory.forLocal(1801);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet());
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/token-pst-unsafe.js'), 'utf8');
|
||||
|
||||
// deploying contract using the new SDK.
|
||||
|
||||
@@ -2,20 +2,20 @@ import fs from 'fs';
|
||||
|
||||
import ArLocal from 'arlocal';
|
||||
import Arweave from 'arweave';
|
||||
import { JWKInterface } from 'arweave/node/lib/wallet';
|
||||
import {JWKInterface} from 'arweave/node/lib/wallet';
|
||||
import path from 'path';
|
||||
import { mineBlock } from '../_helpers';
|
||||
import { Evaluate } from '@idena/vrf-js';
|
||||
import {mineBlock} from '../_helpers';
|
||||
import {Evaluate} from '@idena/vrf-js';
|
||||
import elliptic from 'elliptic';
|
||||
import { PstState, PstContract } from '../../../contract/PstContract';
|
||||
import { InteractionsLoader } from '../../../core/modules/InteractionsLoader';
|
||||
import { EvaluationOptions } from '../../../core/modules/StateEvaluator';
|
||||
import { Warp } from '../../../core/Warp';
|
||||
import { WarpFactory, defaultCacheOptions } from '../../../core/WarpFactory';
|
||||
import { GQLNodeInterface } from '../../../legacy/gqlResult';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
import { ArweaveGatewayInteractionsLoader } from '../../../core/modules/impl/ArweaveGatewayInteractionsLoader';
|
||||
import { LexicographicalInteractionsSorter } from '../../../core/modules/impl/LexicographicalInteractionsSorter';
|
||||
import {PstContract, PstState} from '../../../contract/PstContract';
|
||||
import {InteractionsLoader} from '../../../core/modules/InteractionsLoader';
|
||||
import {EvaluationOptions} from '../../../core/modules/StateEvaluator';
|
||||
import {Warp} from '../../../core/Warp';
|
||||
import {defaultCacheOptions, WarpFactory} from '../../../core/WarpFactory';
|
||||
import {GQLNodeInterface} from '../../../legacy/gqlResult';
|
||||
import {LoggerFactory} from '../../../logging/LoggerFactory';
|
||||
import {ArweaveGatewayInteractionsLoader} from '../../../core/modules/impl/ArweaveGatewayInteractionsLoader';
|
||||
import {LexicographicalInteractionsSorter} from '../../../core/modules/impl/LexicographicalInteractionsSorter';
|
||||
|
||||
const EC = new elliptic.ec('secp256k1');
|
||||
const key = EC.genKeyPair();
|
||||
@@ -65,7 +65,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
.setInteractionsLoader(loader)
|
||||
.build();
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet, address: walletAddress } = await warp.testing.generateWallet());
|
||||
walletAddress = await arweave.wallets.jwkToAddress(wallet);
|
||||
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/token-pst.js'), 'utf8');
|
||||
@@ -82,7 +82,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
}
|
||||
};
|
||||
|
||||
const { contractTxId } = await warp.createContract.deploy({
|
||||
const {contractTxId} = await warp.createContract.deploy({
|
||||
wallet,
|
||||
initState: JSON.stringify(initialState),
|
||||
src: contractSrc
|
||||
@@ -122,7 +122,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
});
|
||||
|
||||
it('should throw if random cannot be verified', async () => {
|
||||
const { originalTxId: txId } = await pst.writeInteraction({
|
||||
const {originalTxId: txId} = await pst.writeInteraction({
|
||||
function: 'vrf'
|
||||
});
|
||||
await mineBlock(warp);
|
||||
@@ -130,7 +130,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
await expect(pst.readState()).rejects.toThrow('Vrf verification failed.');
|
||||
useWrongIndex.pop();
|
||||
|
||||
const { originalTxId: txId2 } = await pst.writeInteraction({
|
||||
const {originalTxId: txId2} = await pst.writeInteraction({
|
||||
function: 'vrf'
|
||||
});
|
||||
await mineBlock(warp);
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('Testing internal writes', () => {
|
||||
warp = WarpFactory.forLocal(port);
|
||||
({ arweave } = warp);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet());
|
||||
|
||||
contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
|
||||
contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('Testing internal writes', () => {
|
||||
|
||||
async function deployContracts() {
|
||||
warp = WarpFactory.forLocal(port);
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
|
||||
callingContractSrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
|
||||
callingContractInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');
|
||||
|
||||
@@ -61,7 +61,6 @@ describe('Testing internal writes', () => {
|
||||
|
||||
let wallet: JWKInterface;
|
||||
|
||||
let arweave: Arweave;
|
||||
let arlocal: ArLocal;
|
||||
let warp: Warp;
|
||||
let calleeContract: Contract<any>;
|
||||
@@ -86,7 +85,7 @@ describe('Testing internal writes', () => {
|
||||
async function deployContracts() {
|
||||
warp = WarpFactory.forLocal(port);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
|
||||
callingContractSrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
|
||||
callingContractInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');
|
||||
|
||||
@@ -60,7 +60,6 @@ describe('Testing internal writes', () => {
|
||||
|
||||
let wallet: JWKInterface;
|
||||
|
||||
let arweave: Arweave;
|
||||
let arlocal: ArLocal;
|
||||
let warp: Warp;
|
||||
let contractA: Contract<any>;
|
||||
@@ -87,7 +86,7 @@ describe('Testing internal writes', () => {
|
||||
async function deployContracts() {
|
||||
warp = WarpFactory.forLocal(port);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
|
||||
contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
|
||||
contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');
|
||||
|
||||
@@ -80,7 +80,7 @@ describe('Testing internal writes', () => {
|
||||
|
||||
async function deployContracts() {
|
||||
warp = WarpFactory.forLocal(port);
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
|
||||
contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
|
||||
contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('Testing the Warp client for AssemblyScript WASM contract', () => {
|
||||
warp = WarpFactory.forLocal(1300);
|
||||
({ arweave } = warp);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
contractSrc = fs.readFileSync(path.join(__dirname, '../data/wasm/as/assemblyscript-counter.wasm'));
|
||||
initialState = fs.readFileSync(path.join(__dirname, '../data/wasm/counter-init-state.json'), 'utf8');
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ describe('Testing the Go WASM Profit Sharing Token', () => {
|
||||
warp = WarpFactory.forLocal(1150);
|
||||
({ arweave } = warp);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet())
|
||||
walletAddress = await arweave.wallets.jwkToAddress(wallet);
|
||||
|
||||
const contractSrc = fs.readFileSync(path.join(__dirname, '../data/wasm/go/go-pst.wasm'));
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('Testing the Rust WASM Profit Sharing Token', () => {
|
||||
({ arweave } = warp);
|
||||
arweaveWrapper = new ArweaveWrapper(arweave);
|
||||
|
||||
wallet = await warp.testing.generateWallet();
|
||||
({ jwk: wallet } = await warp.testing.generateWallet());
|
||||
walletAddress = await arweave.wallets.jwkToAddress(wallet);
|
||||
|
||||
const contractSrc = fs.readFileSync(path.join(__dirname, '../data/wasm/rust/rust-pst_bg.wasm'));
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import Arweave from 'arweave';
|
||||
import { JWKInterface } from 'arweave/node/lib/wallet';
|
||||
|
||||
export type Wallet = {
|
||||
jwk: JWKInterface;
|
||||
address: string;
|
||||
};
|
||||
|
||||
export class Testing {
|
||||
constructor(private readonly arweave: Arweave) {}
|
||||
|
||||
@@ -9,12 +14,15 @@ export class Testing {
|
||||
await this.arweave.api.get('mine');
|
||||
}
|
||||
|
||||
async generateWallet(): Promise<JWKInterface> {
|
||||
async generateWallet(): Promise<Wallet> {
|
||||
this.validateEnv();
|
||||
const wallet = await this.arweave.wallets.generate();
|
||||
await this.addFunds(wallet);
|
||||
|
||||
return wallet;
|
||||
return {
|
||||
jwk: wallet,
|
||||
address: await this.arweave.wallets.jwkToAddress(wallet)
|
||||
};
|
||||
}
|
||||
|
||||
private async addFunds(wallet: JWKInterface) {
|
||||
|
||||
Reference in New Issue
Block a user