Skip to content

Commit

Permalink
Added some helper test files to support tests in "typescripted" branch
Browse files Browse the repository at this point in the history
Signed-off-by: Slava Fomin II <[email protected]>
  • Loading branch information
slavafomin committed Mar 10, 2022
1 parent 7a2732d commit 379f393
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 5 deletions.
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
"homepage": "https://github.com/toncenter/tonweb#readme",
"repository": "https://github.com/toncenter/tonweb",
"dependencies": {
"@ledgerhq/hw-transport-web-ble": "5.48.0",
"@ledgerhq/hw-transport-webhid": "5.48.0",
"@ledgerhq/hw-transport-webusb": "5.48.0",
"bn.js": "5.1.1",
"tweetnacl": "1.0.3",
"ethjs-unit": "0.1.6",
"isomorphic-webcrypto": "2.3.8",
"@ledgerhq/hw-transport-webusb": "5.48.0",
"@ledgerhq/hw-transport-webhid": "5.48.0",
"@ledgerhq/hw-transport-web-ble": "5.48.0",
"node-fetch": "2.6.7"
"node-fetch": "2.6.7",
"tweetnacl": "1.0.3"
},
"devDependencies": {
"@sinonjs/fake-timers": "^9.1.1",
"buffer": "6.0.3",
"webpack": "5.70.0",
"webpack-cli": "3.3.12"
Expand Down
26 changes: 26 additions & 0 deletions test/typescripted/test-http-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

const { default: HttpProvider } = require('../../src/providers/index');


/**
* A stub HTTP Provider that is used in tests.
*/
class TestHttpProvider extends HttpProvider {

constructor() {
super('', {});
}


async send(method, params) {
return new Response('{}', {
status: 200,
statusText: 'OK',
});
}

}

module.exports = {
TestHttpProvider,
};
41 changes: 41 additions & 0 deletions test/typescripted/wallet-v4-contract-r2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

const nacl = require('tweetnacl');

const TonWeb = require('../../src');
const utils = TonWeb.utils;
const { TestHttpProvider } = require('./test-http-provider');


const FakeTimers = require('@sinonjs/fake-timers');
FakeTimers.install();


(async () => {

const testProvider = new TestHttpProvider();

// Address: UQC63Lo54ZfLTGo12UECZc8Ba3g-dEVhvzy7Vroe43-AQzAe
const keyPair = nacl.sign.keyPair.fromSeed(
new Uint8Array(32)
);

const wallet = new TonWeb.Wallets.all.v4R2(
testProvider, {
publicKey: keyPair.publicKey,
}
);

const method = wallet.methods.transfer({
secretKey: keyPair.secretKey,
toAddress: 'UQC63Lo54ZfLTGo12UECZc8Ba3g-dEVhvzy7Vroe43-AQzAe',
amount: 1050,
seqno: 1,
});

const queryCell = await method.getQuery();
const queryBoc = await queryCell.toBoc();
const queryBocB64 = utils.bytesToBase64(queryBoc);

console.log(queryBocB64);

})();

0 comments on commit 379f393

Please sign in to comment.