Skip to content

Commit

Permalink
compiled-test'leri bun ortamında çalıştırılabilir hale getir
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Apr 25, 2024
1 parent cc150a1 commit 35cf5d6
Show file tree
Hide file tree
Showing 34 changed files with 129 additions and 141 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ Bu repoda iki tür test var:

### compiled-test'ler nasıl çalıştırılır?

Örnek olarak `crypto/test/modular.compiled-test.js`'i çalıştırmak için `make build/crypto/test/modular.compiled-test.js` komutunu çalıştırmak gerekir. Sorunsuz çalıştırılması durumunda aşağıdaki gibi bir çıktı oluşur:
`compiled-test`'ler hem GCC ile derlenerek hem de doğrudan `bun` ortamında
çalıştırılabilir.
Örnek olarak `crypto/test/modular.compiled-test.js`'i çalıştırmak için ya
```shell
make build/crypto/test/modular.compiled-test.js
bun build/crypto/test/modular.compiled-test.js
```
yazabiliriz ya da doğrudan
```shell
bun crypto/test/modular.compiled-test.js
```
yazabiliriz. Sorunsuz çalıştırılması durumunda aşağıdaki gibi bir çıktı oluşur:

![](.github/img/modular.compiled-test.png "Örnek modular.compiled-test.js çıktısı")

Expand Down
6 changes: 3 additions & 3 deletions api/test/jsonrpc.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jsonrpc from "/api/jsonrpc";
import evm from "/ethereum/evm";
import { assertEq } from "/testing/assert";
import evm from "../../ethereum/evm";
import { assertEq } from "../../testing/assert";
import jsonrpc from "../jsonrpc";

/** @const {string} */
const OLD_TCKO_ADDR = "0xb97bf95b4f3110285727b70da5a7465bfd2098ca";
Expand Down
4 changes: 2 additions & 2 deletions birimler/test/birim/kpass/birim.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="tc">
KPASS eklendi.
<div id="kp">
KPass eklendi.
<div data-set-id="var1">ID should be var1value</div>
<div data-generate="fibonacci"></div>
<div data-generate="add" data-m="101"></div>
Expand Down
2 changes: 1 addition & 1 deletion birimler/test/okuyucu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("sayfaOku tests", () => {
const sayfa = sayfaOku("ana/sayfa.html", { dil: "tr", dev: true, kök: "birimler/test/" });
expect(sayfa).toContain("ana/sayfa.css");
expect(sayfa).toContain("Cüzdan eklendi");
expect(sayfa).toContain("KPASS eklendi");
expect(sayfa).toContain("KPass eklendi");
expect(sayfa).toContain("birim/kpass/birim.css");

expect(sayfa).toContain("<b>kalın</b>");
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/test/pageWorker.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { create } from "/cloudflare/pageWorker";
import { assertEq } from "/testing/assert";
import { assertEq } from "../../testing/assert";
import { create } from "../pageWorker";

/**
* @constructor
Expand Down
6 changes: 3 additions & 3 deletions crosschain/test/unlockable.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decrypt, encrypt } from "/crosschain/unlockable";
import { assertEq } from "/testing/assert";
import { FakeSigner } from "/testing/crosschain";
import { assertEq } from "../../testing/assert";
import { FakeSigner } from "../../testing/crosschain";
import { decrypt, encrypt } from "../unlockable";

/**
* @return {!Promise<boolean>}
Expand Down
4 changes: 2 additions & 2 deletions crypto/bench/modular.bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exp, exp2, expTimesExp } from "/crypto/modular";
import { assertEq } from "/testing/assert";
import { assertEq } from "../../testing/assert";
import { exp, exp2, expTimesExp } from "../modular";

/**
* @param {!bigint} a
Expand Down
8 changes: 4 additions & 4 deletions crypto/bench/primes.bench.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getNonsmooth, millerRabinBase2 } from "/crypto/primes";
import { keccak256Uint8 } from "/crypto/sha3";
import { assert } from "/testing/assert";
import { hex } from "/util/çevir";
import { assert } from "../../testing/assert";
import { hex } from "../../util/çevir";
import { getNonsmooth, millerRabinBase2 } from "../primes";
import { keccak256Uint8 } from "../sha3";

const benchGetNonsmooth = () => {
console.time("getNonsmooth()");
Expand Down
4 changes: 2 additions & 2 deletions crypto/bench/secp256k1.bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { equal, G, N, O, Point } from "/crypto/secp256k1";
import { assert } from "/testing/assert";
import { assert } from "../assert";
import { equal, G, N, O, Point } from "../secp256k1";

/**
* @param {!Point} P
Expand Down
4 changes: 2 additions & 2 deletions crypto/bench/wesolowski.bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { evaluate } from "/crypto/wesolowski";
import { assertEq } from "/testing/assert";
import { assertEq } from "../../testing/assert";
import { evaluate } from "../wesolowski";

/** @const {!Uint32Array} */
const buff = Uint32Array.from("00000001".repeat(5));
Expand Down
6 changes: 3 additions & 3 deletions crypto/test/integration.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import evm from "/ethereum/evm";
import { assertEq } from "/testing/assert";
import vm from "/testing/vm";
import evm from "../../ethereum/evm";
import { assertEq } from "../../testing/assert";
import vm from "../../testing/vm";

const testAddr = () => {
assertEq(vm.addr(1n), "0x7e5f4552091a69125d5dfcb7b8c2659029395bdf");
Expand Down
4 changes: 2 additions & 2 deletions crypto/test/modular.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exp, exp2, expTimesExp, inverse } from "/crypto/modular";
import { assertEq } from "/testing/assert";
import { assertEq } from "../../testing/assert";
import { exp, exp2, expTimesExp, inverse } from "../modular";

/**
* Prime used in the secp256k1 curve.
Expand Down
4 changes: 2 additions & 2 deletions crypto/test/primes.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNonsmooth, millerRabinBase2, OddPrimes } from "/crypto/primes";
import { assert, assertEq } from "/testing/assert";
import { assert, assertEq } from "../../testing/assert";
import { OddPrimes, getNonsmooth, millerRabinBase2 } from "../primes";

const testMillerRabin = () => {
assertEq(millerRabinBase2(37n, 9n, 2,), true);
Expand Down
4 changes: 2 additions & 2 deletions crypto/test/secp256k1/unit.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { equal, G, N, O, recoverSigner, sign, verify } from "/crypto/secp256k1";
import { assert } from "/testing/assert";
import { assert } from "../../../testing/assert";
import { equal, G, N, O, recoverSigner, sign, verify } from "../../secp256k1";

const testCopy = () => {
const P = G.copy();
Expand Down
6 changes: 3 additions & 3 deletions crypto/test/sha3.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assertArrayEq, assertEq } from "../../testing/assert";
import { hex } from "../../util/çevir";
import { keccak256, keccak256Uint32 } from "../sha3";
import { keccak256 as keccak256_orig } from "./sha3_orig";
import { keccak256 as keccak256_prev } from "./sha3_prev";
import { keccak256, keccak256Uint32 } from "/crypto/sha3";
import { assertArrayEq, assertEq } from "/testing/assert";
import { hex } from "/util/çevir";

const testKeccak256 = () => {
assertEq(
Expand Down
6 changes: 3 additions & 3 deletions crypto/test/wesolowski.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { keccak256Uint32 } from "/crypto/sha3";
import { evaluate, generateChallenge, reconstructY } from "/crypto/wesolowski";
import { assert, assertArrayEq } from "/testing/assert";
import { assert, assertArrayEq } from "../../testing/assert";
import { keccak256Uint32 } from "../sha3";
import { evaluate, generateChallenge, reconstructY } from "../wesolowski";

const testEvaluateReconstruct = () => {
/** @const {number} */
Expand Down
19 changes: 11 additions & 8 deletions did/test/decryptedSections.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { keccak256Uint8 } from "/crypto/sha3";
import { keccak256Uint8 } from "../../crypto/sha3";
import { assert, assertElemEq, assertEq } from "../../testing/assert";
import { FakeSigner, Signer } from "../../testing/crosschain";
import vm from "../../testing/vm";
import { base64 } from "../../util/çevir";
import {
combineMultiple, fromUnlockableNFT, SectionGroup, selectEncryptedSections,
SectionGroup,
combineMultiple,
fromUnlockableNFT,
selectEncryptedSections,
sign,
toUnlockableNFT
} from "/did/decryptedSections";
import { commit, recoverSectionSigners } from "/did/section";
import { assert, assertElemEq, assertEq } from "/testing/assert";
import { FakeSigner, Signer } from "/testing/crosschain";
import vm from "/testing/vm";
import { base64 } from "/util/çevir";
} from "../decryptedSections";
import { commit, recoverSectionSigners } from "../section";

const testSelectEncryptedSections = () => {
/** @const {!Array<string>} */
Expand Down
8 changes: 4 additions & 4 deletions did/test/section.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commit, hash, recoverSectionSigners, signSection } from "/did/section";
import { assertElemEq, assertEq } from "/testing/assert";
import vm from "/testing/vm";
import { base64, hex } from "/util/çevir";
import { assertElemEq, assertEq } from "../../testing/assert";
import vm from "../../testing/vm";
import { base64, hex } from "../../util/çevir";
import { commit, hash, recoverSectionSigners, signSection } from "../section";

const testHash = () => {
{
Expand Down
6 changes: 3 additions & 3 deletions did/test/verifiableID.compiled-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generate, prepareGenerateKey, verify } from "/did/verifiableID";
import { assert } from "/testing/assert";
import { base64 } from "/util/çevir";
import { assert } from "../../testing/assert";
import { base64 } from "../../util/çevir";
import { generate, prepareGenerateKey, verify } from "../verifiableID";

/**
* @return {!Promise<void>}
Expand Down
36 changes: 35 additions & 1 deletion ethereum/KPassLite.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import jsonrpc from "../api/jsonrpc";
import { ChainId } from "../crosschain/chains";
import { address, callMethod, isNonzero } from "./provider";

Expand All @@ -9,7 +10,7 @@ const KPASS_ADDRS = [

/**
* @param {ChainId} chainId
* @return {string} KPASS contract address
* @return {string} KPass contract address
*/
const getAddress = (chainId) => KPASS_ADDRS[+(chainId == ChainId.x144)];

Expand All @@ -31,8 +32,41 @@ const handleOf = (provider, chainId, addr) => chainId.startsWith("m:")
*/
const hasKPass = (provider, chainId, addr) => handleOf(provider, chainId, addr).then(isNonzero);

/**
* TODO(KimlikDAO-bot): Remove dependency on jsonrpc by having a JsonRpcProvider
* which handles fetches.
*
* @param {!Object<ChainId, string>} providerURLs
* @param {!Array<string>} addresses
* @return {!Promise<!Array<boolean>>}
*/
const hasKPasses = (providerURLs, addresses) => {
/** @const {!Array<ChainId>} */
const chains = Object.keys(providerURLs);

/** @const {!Promise<!Array<!Array<boolean>>>} */
const tableByChainPromise = Promise.all(chains.map((chainId) => jsonrpc.callMulti(
"https://" + providerURLs[chainId], "eth_call",
addresses.map((addr) => [
/** @type {!eth.Transaction} */({
to: getAddress(chainId),
data: "0xc50a1514" + address(addr)
}), "latest"
])
).then((/** @type {!Array<string>} */ handles) => handles.map(isNonzero))
));

return tableByChainPromise.then((tableByChain) =>
tableByChain.reduce(
(acc, row) => row.map((item, index) => acc[index] || item),
new Array(addresses.length).fill(false)
)
);
}

export default {
getAddress,
handleOf,
hasKPass,
hasKPasses,
};
51 changes: 0 additions & 51 deletions ethereum/builder/examples/kpass.js

This file was deleted.

6 changes: 0 additions & 6 deletions ethereum/builder/package.json

This file was deleted.

11 changes: 4 additions & 7 deletions ethereum/builder/builder.js → ethereum/evm/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const batchSendFixedAmount = (recipients, amountSzabos) => {
return toByteCode(ops.slice(0, -1));
}


/**
* Generates a batchSend bytecode for an EVM chain that doesn't support
* the PUSH0 opcode.
Expand All @@ -70,7 +69,7 @@ const batchSendFixedAmountNoPush0 = (recipients, amountSzabos) => {
* Generates a batchSend bytecode for an EVM chain that doesn't support
* the PUSH0 opcode.
*
* @param {!Array<AddressAndKPASS>} recipients
* @param {!Array<AddressAndKPass>} recipients
* @param {number} withKPassSzabos
* @param {number} withoutKPassSzabos
* @return {{ code: ByteCode, valueSzabos: number}}
Expand Down Expand Up @@ -109,10 +108,8 @@ export {
Address,
AddressWithKPass,
ByteCode,
SZABO,
batchSendFixedAmount,
SZABO, batchSendERC20, batchSendFixedAmount,
batchSendFixedAmountNoPush0,
batchSendWithKPassNoPush0,
batchSendERC20,
toByteCode
batchSendWithKPassNoPush0, toByteCode
};

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hex } from "@kimlikdao/lib/util/çevir";
import { JsonRpcProvider, Wallet } from "ethers";
import { hex } from "../../../util/çevir";
import { ByteCode, SZABO, batchSendFixedAmountNoPush0 } from "../builder";

/**
Expand All @@ -25,7 +25,7 @@ const batchSend = batchSendFixedAmountNoPush0([
const send = async (program) => {
/**
* @const
* @type {!Provider}
* @type {!JsonRpcProvider}
*/
const provider = new JsonRpcProvider("https://fantom-testnet.rpc.thirdweb.com");
/** @const {!Wallet} */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { shuffle } from "@kimlikdao/lib/util/arrays";
import { hex } from "@kimlikdao/lib/util/çevir";
import { JsonRpcProvider, TransactionResponse, Wallet } from "ethers";
import { shuffle } from "../../../util/arrays";
import { hex } from "../../../util/çevir";
import { SZABO, batchSendWithKPassNoPush0 } from "../builder";

/**
Expand Down Expand Up @@ -40,7 +40,7 @@ const send = () => {

/**
* @const
* @type {!Provider}
* @type {!JsonRpcProvider}
*/
const provider = new JsonRpcProvider("https://rpc.ftm.tools");
/** @const {!Wallet} */
Expand Down
Loading

0 comments on commit 35cf5d6

Please sign in to comment.