Skip to content

Commit

Permalink
refactor: use WireTransaction for Dex (mock)
Browse files Browse the repository at this point in the history
  • Loading branch information
boolafish committed Oct 31, 2019
1 parent dee25da commit e60ca05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
20 changes: 10 additions & 10 deletions plasma_framework/test/endToEndTests/Extendiblility.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ const { expect } = require('chai');
const config = require('../../config.js');

const { EMPTY_BYTES } = require('../helpers/constants.js');
const { PaymentTransactionOutput, PaymentTransaction } = require('../helpers/transaction.js');
const {
PaymentTransactionOutput, PaymentTransaction, WireTransaction,
} = require('../helpers/transaction.js');
const { buildUtxoPos, buildTxPos } = require('../helpers/positions.js');
const Testlang = require('../helpers/testlang.js');
const { MerkleTree } = require('../helpers/merkle.js');
const { buildOutputGuard, computeNormalOutputId } = require('../helpers/utils.js');
const { hashTx } = require('../helpers/paymentEip712.js');
const { sign } = require('../helpers/sign.js');

// first three accounts would be of the order of (deployer, maintainer, authority).
// it is how migration scripts uses the accounts.
// eslint-disable-next-line no-unused-vars
contract.only('PlasmaFramework - Extendibility End to End Tests', ([_, maintainer, authority, richFather]) => {
/**
* First three accounts would be of the order of (deployer, maintainer, authority).
* This is how migration scripts uses the account.
*/
contract('PlasmaFramework - Extendibility End to End Tests', ([_, maintainer, authority, richFather]) => {
const ETH = constants.ZERO_ADDRESS;
const PAYMENT_OUTPUT_V2_TYPE = 2;
const PAYMENT_V2_TX_TYPE = config.registerKeys.txTypes.paymentV2;
Expand All @@ -38,7 +41,7 @@ contract.only('PlasmaFramework - Extendibility End to End Tests', ([_, maintaine
const DUMMY_DEX_NONCE = 123;

const alicePrivateKey = '0x7151e5dab6f8e95b5436515b83f423c4df64fe4c6149f864daa209b26adb10ca';
const venuePrivateKey = '0x7151e5dab6f8e95b5436515b83f423c4df64fe4c6149f864daa209b26adb10cb'
const venuePrivateKey = '0x7151e5dab6f8e95b5436515b83f423c4df64fe4c6149f864daa209b26adb10cb';
let alice;
let venue;

Expand Down Expand Up @@ -184,12 +187,9 @@ contract.only('PlasmaFramework - Extendibility End to End Tests', ([_, maintaine
});

describe('And then transfer from Payment V2 to DEX (mock)', () => {
// TODO: rename PaymentTransaction to WireTransaction?
// Currently cheats using PaymentTransaction/PaymentTransactionOutput as DEX transaction
// They looks the same anyway.
beforeEach(async () => {
// cheat by making the DEX tx no output, not testing the ability to exit DEX anyway
this.dexTxObject = new PaymentTransaction(
this.dexTxObject = new WireTransaction(
DEX_MOCK_TX_TYPE, [this.dexDepositOutputId], [],
);
this.dexTx = this.dexTxObject.rlpEncoded();
Expand Down
14 changes: 10 additions & 4 deletions plasma_framework/test/helpers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const TransactionTypes = {
PLASMA_DEPOSIT: 1,
};

class PaymentTransactionOutput {
class WireTransactionOutput {
constructor(type, amount, outputGuard, token) {
this.outputType = type;
this.outputGuard = outputGuard;
Expand All @@ -28,11 +28,13 @@ class PaymentTransactionOutput {
static parseFromContractOutput(output) {
const amount = parseInt(output.amount, 10);
const outputType = parseInt(output.outputType, 10);
return new PaymentTransactionOutput(outputType, amount, output.outputGuard, output.token);
return new WireTransactionOutput(outputType, amount, output.outputGuard, output.token);
}
}

class PaymentTransaction {
class PaymentTransactionOutput extends WireTransactionOutput {}

class WireTransaction {
constructor(transactionType, inputs, outputs, metaData = EMPTY_BYTES_32) {
this.transactionType = transactionType;
this.inputs = inputs;
Expand All @@ -44,7 +46,7 @@ class PaymentTransaction {
const tx = [this.transactionType];

tx.push(this.inputs);
tx.push(PaymentTransaction.formatForRlpEncoding(this.outputs));
tx.push(WireTransaction.formatForRlpEncoding(this.outputs));
tx.push(this.metaData);

return rlp.encode(tx);
Expand All @@ -59,6 +61,8 @@ class PaymentTransaction {
}
}

class PaymentTransaction extends WireTransaction {}

class PlasmaDepositTransaction extends PaymentTransaction {
constructor(output, metaData = EMPTY_BYTES_32) {
super(TransactionTypes.PLASMA_DEPOSIT, [], [output], metaData);
Expand All @@ -69,4 +73,6 @@ module.exports = {
PaymentTransaction,
PlasmaDepositTransaction,
PaymentTransactionOutput,
WireTransaction,
WireTransactionOutput,
};

0 comments on commit e60ca05

Please sign in to comment.