Skip to content

Commit

Permalink
Remove UI dependency from contract (#111)
Browse files Browse the repository at this point in the history
Fix for integration tests
  • Loading branch information
mhofman authored Jun 14, 2023
2 parents 77f5ef0 + 621559a commit 3952279
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
let branch = 'master';
if (context.payload.pull_request) {
const { body } = context.payload.pull_request;
const regex = /^\#loadgen-branch:\s+(\S+)/m;
const regex = /^\#agoric-sdk-branch:\s+(\S+)/m;
const result = regex.exec(body);
if (result) {
branch = result[1];
Expand All @@ -42,9 +42,9 @@ jobs:
- name: set GOPATH
run: echo GOPATH="$HOME/go" >> $GITHUB_ENV
shell: bash
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'
- name: cache Go modules
uses: actions/cache@v3
id: go-cache
Expand Down
52 changes: 51 additions & 1 deletion loadgen/contract/display.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
import { stringifyNat } from '@agoric/ui-components/src/display/natValue/stringifyNat.js';
// @ts-check
import { assert, details } from '@agoric/assert';

const CONVENTIONAL_DECIMAL_PLACES = 2;

export const roundToDecimalPlaces = (
rightOfDecimalStr = '',
decimalPlaces = 0,
) => {
assert.typeof(rightOfDecimalStr, 'string');
assert.typeof(decimalPlaces, 'number');
assert(
decimalPlaces >= 0,
details`decimalPlaces must be a number greater or equal to 0`,
);
// If rightOfDecimalStr isn't long enough, pad with 0s
const strPadded = rightOfDecimalStr.padEnd(decimalPlaces, '0');
// This is rounding down to the floor
// TODO: round more appropriately, maybe bankers' rounding
const strRounded = strPadded.substring(0, decimalPlaces);
return strRounded;
};

/**
* @param {NatValue | null} natValue
* @param {number} [decimalPlaces]
* @param {number} [placesToShow]
* @returns {string}
*/
export const stringifyNat = (
natValue = null,
decimalPlaces = 0,
placesToShow = CONVENTIONAL_DECIMAL_PLACES,
) => {
if (natValue === null) {
return '';
}
assert.typeof(natValue, 'bigint');
const str = `${natValue}`.padStart(decimalPlaces, '0');
const leftOfDecimalStr = str.substring(0, str.length - decimalPlaces) || '0';
const rightOfDecimalStr = roundToDecimalPlaces(
`${str.substring(str.length - decimalPlaces)}`,
placesToShow,
);

if (rightOfDecimalStr === '') {
return leftOfDecimalStr;
}

return `${leftOfDecimalStr}.${rightOfDecimalStr}`;
};

/**
* @param {Amount<'nat'>} amount
Expand Down
2 changes: 1 addition & 1 deletion loadgen/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"devDependencies": {},
"dependencies": {
"@agoric/assert": "*",
"@agoric/ertp": "*",
"@agoric/notifier": "*",
"@agoric/ui-components": "*",
"@agoric/zoe": "*",
"@endo/eventual-send": "^0.16.9",
"@endo/far": "^0.2.15"
Expand Down
20 changes: 1 addition & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@agoric/assert" "^0.3.15"
n-readlines "^1.0.0"

"@agoric/assert@^0.3.15":
"@agoric/assert@*", "@agoric/assert@^0.3.15":
version "0.3.15"
resolved "https://registry.yarnpkg.com/@agoric/assert/-/assert-0.3.15.tgz#149d120790b76bb79ca9a02f265d8e7a8a904a87"
integrity sha512-6Kb0mtRoAd3O3VwnEXnGpy+ldqD+nB4OSZdgfKZkGn+apN9nLQP4OStEZKeG+jWsgBIzpNE61LrXv6HnBMCX+Q==
Expand Down Expand Up @@ -310,19 +310,6 @@
"@agoric/swingset-vat" "^0.24.0"
"@agoric/zoe" "^0.21.0"

"@agoric/ui-components@*":
version "0.2.27"
resolved "https://registry.yarnpkg.com/@agoric/ui-components/-/ui-components-0.2.27.tgz#0f3ce15618967d645d273a85413b843be9cee2f8"
integrity sha512-YOGnq8bueLT37MclOxzjL9JczJ4wVByUz6NrbiRDt43pU6i33b3bHU4sfuKH1F0zbg/JHMKE+HQSlHjypcN0Xg==
dependencies:
"@agoric/assert" "^0.3.15"
"@agoric/ertp" "^0.13.0"
"@agoric/eventual-send" "^0.14.0"
"@agoric/install-ses" "^0.5.29"
"@agoric/nat" "^4.1.0"
"@agoric/zoe" "^0.21.0"
clsx "^1.1.1"

"@agoric/vats@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@agoric/vats/-/vats-0.5.0.tgz#0d8d43aba10743d4edca86cc71b3275aab3667e5"
Expand Down Expand Up @@ -2650,11 +2637,6 @@ clone@^1.0.2:
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"
integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4=

clsx@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.1.1.tgz#98b3134f9abbdf23b2663491ace13c5c03a73188"
integrity sha512-6/bPho624p3S2pMyvP5kKBPXnI3ufHLObBFCfgx+LkeR5lg2XYy2hqZqUf45ypD8COn2bhgGJSUE+l5dhNBieA==

code-excerpt@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/code-excerpt/-/code-excerpt-3.0.0.tgz#fcfb6748c03dba8431c19f5474747fad3f250f10"
Expand Down

0 comments on commit 3952279

Please sign in to comment.