-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from multiversx/TOOL-248-add-workflow-to-run-…
…integration-tests-with-localnet Add workflow
- Loading branch information
Showing
15 changed files
with
267 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: MultiversX Integration Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
integration_tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Step 1: Checkout the repository | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# Step 2: Set up Python environment | ||
- name: Set up Python 3.x | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
# Step 3: Install pipx (to manage Python tools) | ||
- name: Install pipx | ||
run: | | ||
python3 -m pip install --user pipx | ||
python3 -m pipx ensurepath | ||
# Add the pipx binary location to PATH | ||
echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
shell: bash | ||
|
||
# Step 4: Install mxpy (MultiversX Python SDK) | ||
- name: Install mxpy (MultiversX SDK) | ||
run: | | ||
pipx install multiversx-sdk-cli --force | ||
# Step 5: Set up MultiversX localnet using mxpy | ||
- name: Set up MultiversX localnet | ||
run: | | ||
# Start the local testnet with mxpy | ||
mkdir -p ~/localnet && cd ~/localnet | ||
mxpy localnet setup | ||
nohup mxpy localnet start > localnet.log 2>&1 & echo $! > localnet.pid | ||
sleep 60 # Allow time for the testnet to fully start | ||
# Step 6: Install Node.js and dependencies | ||
- name: Set up Node.js environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16.x' | ||
|
||
- name: Install Node.js dependencies | ||
run: npm install | ||
|
||
# Step 7: Run integration tests | ||
- name: Run integration tests | ||
run: | | ||
npm run tests-localnet | ||
# Step 8: Stop the testnet using the stored PID | ||
- name: Stop MultiversX local testnet | ||
if: success() || failure() | ||
run: | | ||
kill $(cat localnet.pid) || echo "Testnet already stopped" |
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
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,57 @@ | ||
import BigNumber from "bignumber.js"; | ||
import { BigIntType, BigIntValue, ManagedDecimalSignedType, ManagedDecimalSignedValue, U32Value } from "../typesystem"; | ||
import { BinaryCodec } from "./binary"; | ||
import { bufferToBigInt } from "./utils"; | ||
import { SizeOfU32 } from "./constants"; | ||
|
||
export class ManagedDecimalSignedCodec { | ||
private readonly binaryCodec: BinaryCodec; | ||
|
||
constructor(binaryCodec: BinaryCodec) { | ||
this.binaryCodec = binaryCodec; | ||
} | ||
|
||
decodeNested(buffer: Buffer, type: ManagedDecimalSignedType): [ManagedDecimalSignedValue, number] { | ||
const length = buffer.readUInt32BE(0); | ||
const payload = buffer.slice(0, length); | ||
|
||
const result = this.decodeTopLevel(payload, type); | ||
return [result, length]; | ||
} | ||
|
||
decodeTopLevel(buffer: Buffer, type: ManagedDecimalSignedType): ManagedDecimalSignedValue { | ||
if (buffer.length === 0) { | ||
return new ManagedDecimalSignedValue(new BigNumber(0), 0); | ||
} | ||
|
||
if (type.isVariable()) { | ||
const bigintSize = buffer.length - SizeOfU32; | ||
|
||
const [value] = this.binaryCodec.decodeNested(buffer.slice(0, bigintSize), new BigIntType()); | ||
const scale = buffer.readUInt32BE(bigintSize); | ||
|
||
return new ManagedDecimalSignedValue(value.valueOf().shiftedBy(-scale), scale); | ||
} | ||
|
||
const value = bufferToBigInt(buffer); | ||
const metadata = type.getMetadata(); | ||
const scale = metadata !== "usize" ? parseInt(metadata.toString()) : 0; | ||
return new ManagedDecimalSignedValue(value.shiftedBy(-scale), scale); | ||
} | ||
|
||
encodeNested(value: ManagedDecimalSignedValue): Buffer { | ||
let buffers: Buffer[] = []; | ||
const rawValue = new BigIntValue(value.valueOf().shiftedBy(value.getScale())); | ||
if (value.isVariable()) { | ||
buffers.push(Buffer.from(this.binaryCodec.encodeNested(rawValue))); | ||
buffers.push(Buffer.from(this.binaryCodec.encodeNested(new U32Value(value.getScale())))); | ||
} else { | ||
buffers.push(Buffer.from(this.binaryCodec.encodeTopLevel(rawValue))); | ||
} | ||
return Buffer.concat(buffers); | ||
} | ||
|
||
encodeTopLevel(value: ManagedDecimalSignedValue): Buffer { | ||
return this.encodeNested(value); | ||
} | ||
} |
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
Oops, something went wrong.