-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VUL-120 storage watching: mapping (address=> uint)
* VUL-120 Storage watching init commit * VUL-120 Remove web3.js * VUL-120 Create table for state * VUL-120 Sava state to db * VUL-120 Get contract by address hash * VUL-126 Watch for fixed lenth slots (sync old data) * VUL-115 Preimage table in contract watcher * VUL-115 Preimage table in contract watcher * Rework test (#29) * remove old path for tests * add mock for store * add tests for dataService * add full tests for processEvent and processState Co-authored-by: Ilnur Galiev <[email protected]> * VUL-120 Save data to db * add contract parser * add functions toStructure and toFields Co-authored-by: Ilnur Galiev <[email protected]>
- Loading branch information
Showing
31 changed files
with
1,651 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ | |
uri = "http://localhost:5000" | ||
|
||
[watcher] | ||
event = true | ||
header =true | ||
event = true | ||
header = true | ||
storage = true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Address from 'models/data/address'; | ||
import Contract from '../models/contract/contract'; | ||
|
||
export const contractsByAddrHash = { | ||
"emptyStateLeafKey": null, | ||
"someStateLeafKey": { | ||
contractId: 1, | ||
address: "0xAddress", | ||
} | ||
}; | ||
|
||
export const eventsByContractId = { | ||
1: [ | ||
], | ||
3: [{ | ||
name: 'ename' | ||
}], | ||
}; | ||
|
||
export const statesByContractId = { | ||
1: [{ | ||
slot: "slot1", | ||
type: "uint", | ||
}, { | ||
slot: "slot2", | ||
type: "uint", | ||
}] | ||
}; | ||
|
||
export const mockGetContractByAddressHash = jest.fn().mockImplementation(function (addrHash: string) { | ||
return contractsByAddrHash[addrHash]; | ||
}); | ||
|
||
export const mockGetStatesByContractId = jest.fn().mockImplementation(function (contractId: number) { | ||
return statesByContractId[contractId]; | ||
}); | ||
|
||
export const mockGetContracts = jest.fn().mockImplementation(function (): Contract[] { | ||
return [ | ||
{ address: 'address1' } as Contract, | ||
{ address: 'address2' } as Contract, | ||
{ | ||
address: 'address3', | ||
contractId: 3, | ||
events: [1], | ||
abi: [{ | ||
name: 'ename', | ||
inputs: [], | ||
}], | ||
} as Contract, | ||
] | ||
}); | ||
|
||
export const mockGetEventsByContractId = jest.fn().mockImplementation(function (contractId: number) { | ||
return eventsByContractId[contractId]; | ||
}); | ||
|
||
export const mockGetAddressById = jest.fn().mockImplementation(function (addressId: number): Address { | ||
return null; | ||
}); | ||
|
||
export const mockGetAddress = jest.fn().mockImplementation(function (addressString: string): Address { | ||
return { | ||
addressId: 0, | ||
address: addressString, | ||
hash: '' | ||
}; | ||
}); | ||
|
||
export const mockGetStore = jest.fn().mockImplementation(() => { | ||
return { | ||
getContractByAddressHash: mockGetContractByAddressHash, | ||
getStatesByContractId: mockGetStatesByContractId, | ||
getContracts: mockGetContracts, | ||
getEventsByContractId: mockGetEventsByContractId, | ||
getAddressById: mockGetAddressById, | ||
getAddress: mockGetAddress | ||
} | ||
}); | ||
|
||
export default { | ||
getStore: mockGetStore | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class StateConfig1604551153589 implements MigrationInterface { | ||
name = 'StateConfig1604551153589' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "contract"."state" ( | ||
"state_id" SERIAL NOT NULL, | ||
"slot" integer NOT NULL, | ||
"type" character varying NOT NULL, | ||
CONSTRAINT "states_pk" PRIMARY KEY ("state_id") | ||
)`); | ||
await queryRunner.query(`ALTER TABLE "contract"."contracts" ADD "states" integer array`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "contract"."contracts" DROP COLUMN "states"`); | ||
await queryRunner.query(`DROP TABLE "contract"."state"`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class StateProgress1604987750715 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
create table if not exists data.state_progress | ||
( | ||
state_progress_id serial not null | ||
constraint state_progress_pk | ||
primary key, | ||
state_id integer not null | ||
constraint state_progress_states_state_id_fk | ||
references contract.state, | ||
contract_id integer not null | ||
constraint state_progress_contracts_contract_id_fk | ||
references contract.contracts, | ||
block_number integer not null | ||
); | ||
comment on table data.state_progress is 'Sync state progress'; | ||
comment on column data.state_progress.state_id is 'State ID'; | ||
comment on column data.state_progress.contract_id is 'Contract ID'; | ||
comment on column data.state_progress.block_number is 'Number of Block'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "data"."state_progress"`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class Addresses1605072677007 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
create table if not exists data.addresses | ||
( | ||
address_id serial not null | ||
constraint addresses_pk | ||
primary key, | ||
address varchar not null, | ||
hash varchar not null | ||
); | ||
comment on column data.addresses.address_id is 'PK'; | ||
comment on column data.addresses.address is 'Contract address'; | ||
comment on column data.addresses.hash is 'Keccak hash'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable('data.addresses'); | ||
} | ||
|
||
} |
Oops, something went wrong.