Skip to content

Commit

Permalink
fix(sdk): add tx hashes to dispute, settle, propose (UMAprotocol#3834)
Browse files Browse the repository at this point in the history
* improve(sdk): linted sdk dir
  • Loading branch information
daywiss authored Feb 25, 2022
1 parent 6bd28e5 commit 36dd4e3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
14 changes: 7 additions & 7 deletions packages/sdk/src/across/test/rateModel.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("rateModel", function () {
blockSearchConfig.fromBlock
);
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("method called before updating"), true);
}
rateModelDictionary.updateWithEvents(filteredEvents);
Expand All @@ -58,15 +58,15 @@ describe("rateModel", function () {
blockSearchConfig.fromBlock - 1
);
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("before first UpdatedRateModel event"), true);
}

// Cannot fetch rate model when dictionary has no entries for L1 token.
try {
await rateModelDictionary.getRateModelForBlockNumber(rateModelStore.address, blockSearchConfig.fromBlock - 1);
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("No updated rate model events for L1 token"), true);
}

Expand Down Expand Up @@ -113,7 +113,7 @@ describe("rateModel", function () {
try {
await rateModelDictionary.getL1TokensFromRateModel(blockSearchConfig.fromBlock);
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("method called before updating"), true);
}
rateModelDictionary.updateWithEvents(filteredEvents);
Expand All @@ -139,7 +139,7 @@ describe("rateModel", function () {
try {
rateModel.parseAndReturnRateModelFromString("not a JSON");
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("JSON"), true);
}

Expand All @@ -154,7 +154,7 @@ describe("rateModel", function () {
try {
rateModel.parseAndReturnRateModelFromString(JSON.stringify(rateModelWithMissingKeys));
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("does not contain all expected keys"), true);
}

Expand All @@ -165,7 +165,7 @@ describe("rateModel", function () {
try {
rateModel.parseAndReturnRateModelFromString(JSON.stringify(rateModelWithExtraKeys));
assert.fail("Should throw error");
} catch (err: any) {
} catch (err) {
assert.equal(err.message.includes("contains unexpected keys"), true);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Sets the currently logged in user. This allows partial updates. Returns a string
Clears the current user.
`client.clearUser(): string `
`client.clearUser(): string`
### setActiveRequest
Expand Down
11 changes: 9 additions & 2 deletions packages/sdk/src/oracle/services/statemachines/disputePrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ export function Handlers(store: Store): GenericHandlers<Params, Memory> {
// wait x seconds before running this state again
return context.sleep(checkTxIntervalSec * 1000);
},
async update(params: Params) {
const { chainId, currency, account } = params;
async update(params: Params, memory: Memory) {
const { chainId, currency, account, requester, identifier, timestamp, ancillaryData } = params;
const { hash } = memory;
await update.balance(chainId, currency, account);
await update.request(params);
store.write((w) =>
w
.chains(chainId)
.optimisticOracle()
.request({ chainId, requester, identifier, timestamp, ancillaryData, disputeTx: hash })
);
return "done";
},
};
Expand Down
11 changes: 9 additions & 2 deletions packages/sdk/src/oracle/services/statemachines/proposePrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ export function Handlers(store: Store): GenericHandlers<Params, Memory> {
// wait x seconds before running this state again
return context.sleep(checkTxIntervalSec * 1000);
},
async update(params: Params) {
const { chainId, currency, account } = params;
async update(params: Params, memory: Memory) {
const { chainId, currency, account, requester, identifier, timestamp, ancillaryData } = params;
const { hash } = memory;
await update.balance(chainId, currency, account);
await update.request(params);
store.write((w) =>
w
.chains(chainId)
.optimisticOracle()
.request({ chainId, requester, identifier, timestamp, ancillaryData, proposeTx: hash })
);
return "done";
},
};
Expand Down
11 changes: 9 additions & 2 deletions packages/sdk/src/oracle/services/statemachines/settle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ export function Handlers(store: Store): GenericHandlers<Params, Memory> {
// wait x seconds before running this state again
return context.sleep(checkTxIntervalSec * 1000);
},
async update(params: Params) {
const { chainId, currency, account } = params;
async update(params: Params, memory: Memory) {
const { chainId, currency, account, requester, identifier, timestamp, ancillaryData } = params;
const { hash } = memory;
await update.balance(chainId, currency, account);
await update.request(params);
store.write((w) =>
w
.chains(chainId)
.optimisticOracle()
.request({ chainId, requester, identifier, timestamp, ancillaryData, settleTx: hash })
);
return "done";
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Create a new folder named after the type of data you are storing in the tables d

- README.md: Add some notes on what the table is for and any stores it can use
- index.ts: Expose your tables based on the name type of store it uses, for example `export {default as JsMap} from './js-map'`
- ${store-type}.ts: Create a table file named for the store its compatible with, for example `js-map.ts`
- ${store-type}.test.ts: Any tests you want to run
- \${store-type}.ts: Create a table file named for the store its compatible with, for example `js-map.ts`
- \${store-type}.test.ts: Any tests you want to run

See the [blocks table](./blocks/README.md) as an example.

Expand Down

0 comments on commit 36dd4e3

Please sign in to comment.