diff --git a/common/protocol/src/index.ts b/common/protocol/src/index.ts index e497b26d..aacae7ee 100644 --- a/common/protocol/src/index.ts +++ b/common/protocol/src/index.ts @@ -44,7 +44,6 @@ import { waitForCacheContinuation, waitForNextBundleProposal, waitForUploadInterval, - getProxyAuth, isStorageBalanceLow, } from "./methods"; import { ICacheProvider, IMetrics, IRuntime } from "./types"; @@ -124,7 +123,6 @@ export class Validator { // helpers protected archiveDebugBundle = archiveDebugBundle; protected continueRound = continueRound; - public getProxyAuth = getProxyAuth; // txs protected claimUploaderRole = claimUploaderRole; @@ -152,9 +150,9 @@ export class Validator { protected runCache = runCache; // factories - public static cacheProviderFactory = cacheProviderFactory; - public static storageProviderFactory = storageProviderFactory; - public static compressionFactory = compressionFactory; + protected cacheProviderFactory = cacheProviderFactory; + protected storageProviderFactory = storageProviderFactory; + protected compressionFactory = compressionFactory; /** * Constructor for the validator class. It is required to provide the @@ -315,6 +313,9 @@ export class Validator { process.exit(1); } + await this.setupValidator(); + await this.setupCacheProvider(); + if (await this.isStorageBalanceZero()) { process.exit(1); } @@ -323,9 +324,6 @@ export class Validator { process.exit(1); } - await this.setupValidator(); - await this.setupCacheProvider(); - // start the node process. Validator and cache should run at the same time. // Thats why, although they are async they are called synchronously try { diff --git a/common/protocol/src/methods/checks/isStorageBalanceLow.ts b/common/protocol/src/methods/checks/isStorageBalanceLow.ts index 41fcccaf..71ce1722 100644 --- a/common/protocol/src/methods/checks/isStorageBalanceLow.ts +++ b/common/protocol/src/methods/checks/isStorageBalanceLow.ts @@ -11,10 +11,8 @@ import { Validator, standardizeJSON } from "../.."; */ export async function isStorageBalanceLow(this: Validator): Promise { try { - const storageProvider = Validator.storageProviderFactory( - this.pool.data?.current_storage_provider_id ?? 0, - this.storagePriv - ); + this.logger.debug(`this.storageProviderFactory()`); + const storageProvider = this.storageProviderFactory(); this.logger.info( `Checking account balance on StorageProvider:${storageProvider.name}` diff --git a/common/protocol/src/methods/checks/isStorageBalanceZero.ts b/common/protocol/src/methods/checks/isStorageBalanceZero.ts index a0064d49..1d79cb51 100644 --- a/common/protocol/src/methods/checks/isStorageBalanceZero.ts +++ b/common/protocol/src/methods/checks/isStorageBalanceZero.ts @@ -11,10 +11,8 @@ import { Validator, standardizeError } from "../.."; */ export async function isStorageBalanceZero(this: Validator): Promise { try { - const storageProvider = Validator.storageProviderFactory( - this.pool.data?.current_storage_provider_id ?? 0, - this.storagePriv - ); + this.logger.debug(`this.storageProviderFactory()`); + const storageProvider = this.storageProviderFactory(); this.logger.info( `Checking account balance on StorageProvider:${storageProvider.name}` diff --git a/common/protocol/src/methods/helpers/getProxyAuth.ts b/common/protocol/src/methods/helpers/getProxyAuth.ts deleted file mode 100644 index c8cb1f43..00000000 --- a/common/protocol/src/methods/helpers/getProxyAuth.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Validator } from "../.."; - -/** - * getProxyAuth is used for authenticating the protocol node - * for the proxy by signing messages including the pool id - * the validator is currently in - * - * @method getProxyAuth - * @param {Validator} this - * @return {Promise<{ [key: string]: string | number; }>} - */ -export async function getProxyAuth( - this: Validator -): Promise<{ [key: string]: string | number }> { - const address = this.client[0].account.address; - const timestamp = new Date().valueOf().toString(); - const poolId = this.pool.id; - - const { signature, pub_key } = await this.client[0].signString( - `${address}//${poolId}//${timestamp}` - ); - - return { - "Content-Type": "application/json", - Signature: `${signature}`, - "Public-Key": pub_key.value, - "Pool-ID": poolId, - Timestamp: timestamp, - }; -} diff --git a/common/protocol/src/methods/index.ts b/common/protocol/src/methods/index.ts index 1712766f..50ab99f1 100644 --- a/common/protocol/src/methods/index.ts +++ b/common/protocol/src/methods/index.ts @@ -23,7 +23,6 @@ export * from "./timeouts/waitForUploadInterval"; // helpers export * from "./helpers/archiveDebugBundle"; export * from "./helpers/continueRound"; -export * from "./helpers/getProxyAuth"; // txs export * from "./txs/claimUploaderRole"; diff --git a/common/protocol/src/methods/queries/getBalancesForMetrics.ts b/common/protocol/src/methods/queries/getBalancesForMetrics.ts index 93c9297c..42e4f6db 100644 --- a/common/protocol/src/methods/queries/getBalancesForMetrics.ts +++ b/common/protocol/src/methods/queries/getBalancesForMetrics.ts @@ -70,15 +70,8 @@ export async function getBalancesForMetrics(this: Validator): Promise { try { // get current storage provider defined on pool - this.logger.debug( - `storageProviderFactory(${ - this.pool.data?.current_storage_provider_id ?? 0 - }, $STORAGE_PRIV)` - ); - const storageProvider = Validator.storageProviderFactory( - this.pool.data?.current_storage_provider_id ?? 0, - this.storagePriv - ); + this.logger.debug(`this.storageProviderFactory()`); + const storageProvider = this.storageProviderFactory(); this.logger.debug(`this.storageProvider.getBalance()`); diff --git a/common/protocol/src/methods/setups/setupCacheProvider.ts b/common/protocol/src/methods/setups/setupCacheProvider.ts index 686a8524..1321f6a9 100644 --- a/common/protocol/src/methods/setups/setupCacheProvider.ts +++ b/common/protocol/src/methods/setups/setupCacheProvider.ts @@ -19,7 +19,7 @@ export async function setupCacheProvider(this: Validator): Promise { this.logger.debug(`Initializing cache provider with path ${cachePath}`); // create cache provider depending on chosen cache type - this.cacheProvider = Validator.cacheProviderFactory(this.cache); + this.cacheProvider = this.cacheProviderFactory(); // delete all contents of cache directory await fse.emptyDir(`${cachePath}/`); diff --git a/common/protocol/src/methods/upload/createBundleProposal.ts b/common/protocol/src/methods/upload/createBundleProposal.ts index b6b426ed..ad00597d 100644 --- a/common/protocol/src/methods/upload/createBundleProposal.ts +++ b/common/protocol/src/methods/upload/createBundleProposal.ts @@ -104,12 +104,8 @@ export async function createBundleProposal(this: Validator): Promise { } // get current compression defined on pool - this.logger.debug( - `compressionFactory(${this.pool.data?.current_compression_id ?? 0})` - ); - const compression = Validator.compressionFactory( - this.pool.data?.current_compression_id ?? 0 - ); + this.logger.debug(`this.compressionFactory()`); + const compression = this.compressionFactory(); const uploadBundle = bundleToBytes(bundleProposal); @@ -209,15 +205,8 @@ export async function createBundleProposal(this: Validator): Promise { // uploader role to prevent upload slashes try { // get current storage provider defined on pool - this.logger.debug( - `storageProviderFactory(${ - this.pool.data?.current_storage_provider_id ?? 0 - }, $STORAGE_PRIV)` - ); - const storageProvider = Validator.storageProviderFactory( - this.pool.data?.current_storage_provider_id ?? 0, - this.storagePriv - ); + this.logger.debug(`this.storageProviderFactory()`); + const storageProvider = this.storageProviderFactory(); // if balance is less than the upload cost we skip the uploader // role with a warning diff --git a/common/protocol/src/methods/validate/saveBundleDecompress.ts b/common/protocol/src/methods/validate/saveBundleDecompress.ts index bfaaeb6f..6add016f 100644 --- a/common/protocol/src/methods/validate/saveBundleDecompress.ts +++ b/common/protocol/src/methods/validate/saveBundleDecompress.ts @@ -17,12 +17,8 @@ export async function saveBundleDecompress( ): Promise { try { // get compression the proposed bundle was compressed with - this.logger.debug( - `compressionFactory(${this.pool.bundle_proposal?.compression_id ?? 0})` - ); - const compression = Validator.compressionFactory( - this.pool.bundle_proposal?.compression_id ?? 0 - ); + this.logger.debug(`this.compressionFactory()`); + const compression = this.compressionFactory(); this.logger.debug(`this.compression.decompress($RAW_STORAGE_DATA)`); diff --git a/common/protocol/src/methods/validate/saveBundleDownload.ts b/common/protocol/src/methods/validate/saveBundleDownload.ts index 319ab1bc..46accf4e 100644 --- a/common/protocol/src/methods/validate/saveBundleDownload.ts +++ b/common/protocol/src/methods/validate/saveBundleDownload.ts @@ -53,15 +53,8 @@ export async function saveBundleDownload( } // get storage provider the proposed bundle was saved to - this.logger.debug( - `storageProviderFactory(${ - this.pool.bundle_proposal?.storage_provider_id ?? 0 - }, $STORAGE_PRIV)` - ); - const storageProvider = Validator.storageProviderFactory( - this.pool.bundle_proposal?.storage_provider_id ?? 0, - this.storagePriv - ); + this.logger.debug(`this.storageProviderFactory()`); + const storageProvider = this.storageProviderFactory(); // calculate download timeout for storage provider // the timeout should always be 20 seconds less than the upload interval diff --git a/common/protocol/src/reactors/cacheProvider/index.ts b/common/protocol/src/reactors/cacheProvider/index.ts index bb53dc00..89a105fc 100644 --- a/common/protocol/src/reactors/cacheProvider/index.ts +++ b/common/protocol/src/reactors/cacheProvider/index.ts @@ -1,4 +1,4 @@ -import { ICacheProvider } from "../.."; +import { ICacheProvider, Validator } from "../.."; import { JsonFileCache } from "./JsonFileCache"; import { MemoryCache } from "./MemoryCache"; @@ -10,14 +10,13 @@ import { MemoryCache } from "./MemoryCache"; * x - Memory (default) * * @method cacheProviderFactory - * @param {string} cacheId the id of the compression * @return {ICacheProvider} */ -export const cacheProviderFactory = (cacheId: string): ICacheProvider => { - switch (cacheId) { +export function cacheProviderFactory(this: Validator): ICacheProvider { + switch (this.cache) { case "jsonfile": return new JsonFileCache(); default: return new MemoryCache(); } -}; +} diff --git a/common/protocol/src/reactors/compression/index.ts b/common/protocol/src/reactors/compression/index.ts index 99394895..252a3118 100644 --- a/common/protocol/src/reactors/compression/index.ts +++ b/common/protocol/src/reactors/compression/index.ts @@ -1,4 +1,4 @@ -import { ICompression } from "../.."; +import { ICompression, Validator } from "../.."; import { Gzip } from "./Gzip"; import { NoCompression } from "./NoCompression"; @@ -11,14 +11,13 @@ import { NoCompression } from "./NoCompression"; * x - NoCompression (default) * * @method compressionFactory - * @param {number} compressionId the id of the compression * @return {ICompression} */ -export const compressionFactory = (compressionId: number): ICompression => { - switch (compressionId) { +export function compressionFactory(this: Validator): ICompression { + switch (this.pool.data?.current_compression_id ?? 0) { case 1: return new Gzip(); default: return new NoCompression(); } -}; +} diff --git a/common/protocol/src/reactors/storageProviders/Kyve.ts b/common/protocol/src/reactors/storageProviders/Kyve.ts new file mode 100644 index 00000000..21f829cb --- /dev/null +++ b/common/protocol/src/reactors/storageProviders/Kyve.ts @@ -0,0 +1,109 @@ +import KyveSDK from "@kyvejs/sdk"; +import { v4 as uuidv4 } from "uuid"; +import axios from "axios"; +import { BundleTag, IStorageProvider } from "../../types"; + +require("dotenv").config(); + +export class Kyve implements IStorageProvider { + public name = "Kyve"; + public coinDecimals = 0; + + private chainId: string; + private poolId: number; + private staker: string; + private valaccount: string; + + constructor( + chainId: string, + poolId: number, + staker: string, + valaccount: string + ) { + if (!chainId) { + throw new Error("ChainId is empty."); + } + + if (poolId === null || poolId === undefined) { + throw new Error("PoolId is empty."); + } + + if (!staker) { + throw new Error("Staker is empty."); + } + + if (!valaccount) { + throw new Error("Valaccount mnemonic is empty."); + } + + this.chainId = chainId; + this.poolId = poolId; + this.staker = staker; + this.valaccount = valaccount; + } + + async getAddress() { + return (await new KyveSDK().fromMnemonic(this.valaccount)).account.address; + } + + async getBalance() { + return ""; + } + + async getPrice(_: number) { + return "0"; + } + + async saveBundle(bundle: Buffer, _: BundleTag[]) { + const storageId = uuidv4(); + const sdk = await new KyveSDK().fromMnemonic(this.valaccount); + const address = await this.getAddress(); + const timestamp = new Date().valueOf().toString(); + + const { signature, pub_key } = await sdk.signString( + JSON.stringify({ + chainId: this.chainId, + poolId: this.poolId.toString(), + staker: this.staker, + valaccount: address, + timestamp, + }) + ); + + await axios.post( + "https://upload.storage.kyve.network/upload", + { + name: storageId, + data: bundle.toString("base64"), + }, + { + headers: { + "kyve-api-key": process.env.KYVE_STORAGE_PROVIDER_API_KEY || "", + "kyve-chain-id": this.chainId, + "kyve-pool-id": this.poolId.toString(), + "kyve-staker": this.staker, + "kyve-public-key": pub_key.value, + "kyve-timestamp": timestamp, + "kyve-signature": signature, + }, + } + ); + + return { + storageId: storageId, + storageData: bundle, + }; + } + + async retrieveBundle(storageId: string, timeout: number) { + const { data: storageData } = await axios.get( + `https://storage.kyve.network/${storageId}`, + { responseType: "arraybuffer", timeout } + ); + + return { + storageId, + storageData, + }; + } +} diff --git a/common/protocol/src/reactors/storageProviders/S3.ts b/common/protocol/src/reactors/storageProviders/S3.ts deleted file mode 100644 index f42536ee..00000000 --- a/common/protocol/src/reactors/storageProviders/S3.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { - GetObjectCommand, - PutObjectCommand, - S3Client, -} from "@aws-sdk/client-s3"; -import { v4 as uuidv4 } from "uuid"; -import { BundleTag, IStorageProvider } from "../../types"; - -export class S3 implements IStorageProvider { - public name = "S3"; - public coinDecimals = 0; - - private readonly region: string; - private readonly bucket: string; - private readonly s3Client: S3Client; - - constructor() { - this.region = process.env.AWS_REGION || ""; - if (!this.region) { - throw new Error("Env variable AWS_REGION not defined."); - } - - this.bucket = process.env.AWS_BUCKET || ""; - if (!this.region) { - throw new Error("Env variable AWS_BUCKET not defined."); - } - - if (!process.env.AWS_ACCESS_KEY_ID) { - throw new Error("Env variable AWS_ACCESS_KEY_ID not defined."); - } - - if (!process.env.AWS_SECRET_ACCESS_KEY) { - throw new Error("Env variable AWS_SECRET_ACCESS_KEY not defined."); - } - - this.s3Client = new S3Client({ region: this.region }); - } - - async getAddress() { - return this.s3Client.config.region as string; - } - - async getBalance() { - return ""; - } - - async getPrice(_: number) { - return "0"; - } - - async saveBundle(bundle: Buffer, _: BundleTag[]) { - const storageId = uuidv4(); - - await this.s3Client.send( - new PutObjectCommand({ - Bucket: this.bucket, - Key: storageId, - Body: bundle, - }) - ); - - return { - storageId: storageId, - storageData: bundle, - }; - } - - async retrieveBundle(storageId: string, _: number) { - const response = await this.s3Client.send( - new GetObjectCommand({ - Bucket: this.bucket, - Key: storageId, - }) - ); - - const data = - (await response.Body?.transformToByteArray()) ?? new Uint8Array(); - - return { - storageId, - storageData: Buffer.from(data), - }; - } -} diff --git a/common/protocol/src/reactors/storageProviders/index.ts b/common/protocol/src/reactors/storageProviders/index.ts index 8ac5f7ed..5355ffec 100644 --- a/common/protocol/src/reactors/storageProviders/index.ts +++ b/common/protocol/src/reactors/storageProviders/index.ts @@ -1,7 +1,7 @@ -import { IStorageProvider } from "../.."; +import { IStorageProvider, Validator } from "../.."; import { Arweave } from "./Arweave"; import { Bundlr } from "./Bundlr"; -import { S3 } from "./S3"; +import { Kyve } from "./Kyve"; import { NoStorageProvider } from "./NoStorageProvider"; /** @@ -11,26 +11,21 @@ import { NoStorageProvider } from "./NoStorageProvider"; * 0 - NoStorageProvider * 1 - Arweave * 2 - Bundlr - * 3 - AWS S3 + * 3 - Kyve * x - NoStorageProvider (default) * * @method storageProviderFactory - * @param {number} storageProviderId the id of the storage provider - * @param {string} storagePriv the secret used for the storage provider * @return {IStorageProvider} */ -export const storageProviderFactory = ( - storageProviderId: number, - storagePriv: string -): IStorageProvider => { - switch (storageProviderId) { +export function storageProviderFactory(this: Validator): IStorageProvider { + switch (this.pool.data?.current_storage_provider_id ?? 0) { case 1: - return new Arweave(storagePriv); + return new Arweave(this.storagePriv); case 2: - return new Bundlr(storagePriv); + return new Bundlr(this.storagePriv); case 3: - return new S3(); + return new Kyve(this.chainId, this.poolId, this.staker, this.valaccount); default: return new NoStorageProvider(); } -}; +} diff --git a/common/protocol/test/cache.test.ts b/common/protocol/test/cache.test.ts index 4c14a254..1541fa19 100644 --- a/common/protocol/test/cache.test.ts +++ b/common/protocol/test/cache.test.ts @@ -51,15 +51,11 @@ describe("cache tests", () => { // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock process.exit processExit = jest.fn(); diff --git a/common/protocol/test/checks/is_storage_balance_low.test.ts b/common/protocol/test/checks/is_storage_balance_low.test.ts index 8d6674c7..ea5f6ae9 100644 --- a/common/protocol/test/checks/is_storage_balance_low.test.ts +++ b/common/protocol/test/checks/is_storage_balance_low.test.ts @@ -53,9 +53,7 @@ describe("isStorageBalanceLow", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("0"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); v.pool.bundle_proposal!.data_size = "0"; @@ -70,9 +68,7 @@ describe("isStorageBalanceLow", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("100"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); v.pool.bundle_proposal!.data_size = "0"; @@ -87,9 +83,7 @@ describe("isStorageBalanceLow", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("0"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); v.pool.bundle_proposal!.data_size = "100"; @@ -104,9 +98,7 @@ describe("isStorageBalanceLow", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("100"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); v.pool.bundle_proposal!.data_size = "100"; @@ -121,9 +113,7 @@ describe("isStorageBalanceLow", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("5000"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); v.pool.bundle_proposal!.data_size = "100"; @@ -139,9 +129,7 @@ describe("isStorageBalanceLow", () => { storageProvider = new TestNormalStorageProvider(); storageProvider.getAddress = jest.fn().mockRejectedValue(new Error()); storageProvider.getBalance = jest.fn().mockResolvedValue("100"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // ACT await isStorageBalanceLow.call(v); @@ -154,9 +142,7 @@ describe("isStorageBalanceLow", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockRejectedValue(new Error()); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // ACT await isStorageBalanceLow.call(v); diff --git a/common/protocol/test/checks/is_storage_balance_zero.test.ts b/common/protocol/test/checks/is_storage_balance_zero.test.ts index 2eb5362c..f61a2713 100644 --- a/common/protocol/test/checks/is_storage_balance_zero.test.ts +++ b/common/protocol/test/checks/is_storage_balance_zero.test.ts @@ -50,9 +50,7 @@ describe("isStorageBalanceZero", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("0"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // ACT const result = await isStorageBalanceZero.call(v); @@ -65,9 +63,7 @@ describe("isStorageBalanceZero", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("100"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // ACT const result = await isStorageBalanceZero.call(v); @@ -81,9 +77,7 @@ describe("isStorageBalanceZero", () => { storageProvider = new TestNormalStorageProvider(); storageProvider.getAddress = jest.fn().mockRejectedValue(new Error()); storageProvider.getBalance = jest.fn().mockResolvedValue("100"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // ACT const result = await isStorageBalanceZero.call(v); @@ -96,9 +90,7 @@ describe("isStorageBalanceZero", () => { // ARRANGE storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockRejectedValue(new Error()); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // ACT const result = await isStorageBalanceZero.call(v); diff --git a/common/protocol/test/fallback.test.ts b/common/protocol/test/fallback.test.ts index af304d5a..81e6d7c1 100644 --- a/common/protocol/test/fallback.test.ts +++ b/common/protocol/test/fallback.test.ts @@ -46,15 +46,11 @@ describe("fallback tests", () => { // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock process.exit processExit = jest.fn(); diff --git a/common/protocol/test/genesis.test.ts b/common/protocol/test/genesis.test.ts index 0d5642ea..0f6a87ae 100644 --- a/common/protocol/test/genesis.test.ts +++ b/common/protocol/test/genesis.test.ts @@ -45,23 +45,17 @@ describe("genesis tests", () => { // mock cache provider cacheProvider = new TestCacheProvider(); - jest - .spyOn(Validator, "cacheProviderFactory") - .mockImplementation(() => cacheProvider); + v["cacheProviderFactory"] = jest.fn().mockReturnValue(cacheProvider); v["cacheProvider"] = cacheProvider; // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock process.exit processExit = jest.fn(); diff --git a/common/protocol/test/propose_bundle.test.ts b/common/protocol/test/propose_bundle.test.ts index 305b8431..01abe559 100644 --- a/common/protocol/test/propose_bundle.test.ts +++ b/common/protocol/test/propose_bundle.test.ts @@ -50,15 +50,11 @@ describe("propose bundle tests", () => { // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock process.exit processExit = jest.fn(); @@ -288,9 +284,7 @@ describe("propose bundle tests", () => { storageProvider = new TestNormalStorageProvider(); storageProvider.getBalance = jest.fn().mockResolvedValue("0"); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); v["syncPoolState"] = jest.fn().mockImplementation(() => { v.pool = { diff --git a/common/protocol/test/vote_abstain.test.ts b/common/protocol/test/vote_abstain.test.ts index 946245ed..a6d87354 100644 --- a/common/protocol/test/vote_abstain.test.ts +++ b/common/protocol/test/vote_abstain.test.ts @@ -56,23 +56,17 @@ describe("vote abstain tests", () => { // mock cache provider cacheProvider = new TestCacheProvider(); - jest - .spyOn(Validator, "cacheProviderFactory") - .mockImplementation(() => cacheProvider); + v["cacheProviderFactory"] = jest.fn().mockReturnValue(cacheProvider); v["cacheProvider"] = cacheProvider; // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock process.exit processExit = jest.fn(); diff --git a/common/protocol/test/vote_invalid.test.ts b/common/protocol/test/vote_invalid.test.ts index c2ffe058..09745314 100644 --- a/common/protocol/test/vote_invalid.test.ts +++ b/common/protocol/test/vote_invalid.test.ts @@ -54,15 +54,11 @@ describe("invalid votes tests", () => { // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock archiveDebugBundle v["archiveDebugBundle"] = jest.fn(); diff --git a/common/protocol/test/vote_valid.test.ts b/common/protocol/test/vote_valid.test.ts index 067c6985..f3391911 100644 --- a/common/protocol/test/vote_valid.test.ts +++ b/common/protocol/test/vote_valid.test.ts @@ -49,15 +49,11 @@ describe("vote valid tests", () => { // mock storage provider storageProvider = new TestNormalStorageProvider(); - jest - .spyOn(Validator, "storageProviderFactory") - .mockImplementation(() => storageProvider); + v["storageProviderFactory"] = jest.fn().mockReturnValue(storageProvider); // mock compression compression = new TestNormalCompression(); - jest - .spyOn(Validator, "compressionFactory") - .mockImplementation(() => compression); + v["compressionFactory"] = jest.fn().mockReturnValue(compression); // mock process.exit processExit = jest.fn(); diff --git a/integrations/tendermint/package.json b/integrations/tendermint/package.json index c8b20c33..26f44ba2 100644 --- a/integrations/tendermint/package.json +++ b/integrations/tendermint/package.json @@ -24,7 +24,8 @@ "dependencies": { "@kyvejs/protocol": "1.0.3", "ajv": "^8.12.0", - "axios": "^0.27.2" + "axios": "^0.27.2", + "dotenv": "^16.3.1" }, "devDependencies": { "pkg": "^5.8.0", diff --git a/yarn.lock b/yarn.lock index a4cb238f..d087bec5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4812,7 +4812,7 @@ dot-prop@^5.1.0: dependencies: is-obj "^2.0.0" -dotenv@^16.0.3: +dotenv@^16.0.3, dotenv@^16.3.1: version "16.3.1" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==