-
Notifications
You must be signed in to change notification settings - Fork 2
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 #11 from ElrondNetwork/development-07-08
Decoupling / refactoring and new mocks
- Loading branch information
Showing
28 changed files
with
654 additions
and
196 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 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
File renamed without changes.
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
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 { DefaultGasConfiguration, GasEstimator, TransactionFactory, TransactionWatcher } from "@elrondnetwork/erdjs"; | ||
import { ProxyNetworkProvider } from "@elrondnetwork/erdjs-network-providers/out"; | ||
import { FiveMinutesInMilliseconds, IAddress, INetworkConfig, ITestSession, ITestUser, ITransaction, TestSession } from "@elrondnetwork/erdjs-snippets"; | ||
import { assert } from "chai"; | ||
import { createAdderInteractor } from "./adderInteractor"; | ||
|
||
// For testing this scenario, a localnet should be used, with altered code (waits / time.Sleep() in processing). | ||
describe("partial", async function () { | ||
this.bail(true); | ||
|
||
let session: ITestSession; | ||
let networkProvider: ProxyNetworkProvider; | ||
let networkConfig: INetworkConfig; | ||
let transactionFactory: TransactionFactory; | ||
let transactionWatcher: TransactionWatcher; | ||
|
||
// shard(alice) = 1 | ||
// shard(bob) = 0 | ||
let whale: ITestUser; | ||
let alice: ITestUser; | ||
let bob: ITestUser; | ||
|
||
this.beforeAll(async function () { | ||
session = await TestSession.load("localnet", __dirname); | ||
await session.syncNetworkConfig(); | ||
|
||
networkProvider = <ProxyNetworkProvider>session.networkProvider; | ||
networkConfig = session.getNetworkConfig(); | ||
transactionFactory = new TransactionFactory(new GasEstimator(DefaultGasConfiguration)); | ||
transactionWatcher = new TransactionWatcher(networkProvider); | ||
|
||
whale = session.users.getUser("whale"); | ||
alice = session.users.getUser("alice"); | ||
bob = session.users.getUser("bob"); | ||
}); | ||
|
||
this.beforeEach(async function () { | ||
session.correlation.step = this.currentTest?.fullTitle() || ""; | ||
}); | ||
|
||
it("setup", async function () { | ||
this.timeout(FiveMinutesInMilliseconds); | ||
|
||
await session.syncUsers([alice, bob]); | ||
|
||
let addressInShard0 = await deploy(bob); | ||
await session.saveAddress({ name: "adderInShard0", address: addressInShard0 }); | ||
|
||
let addressInShard1 = await deploy(alice); | ||
await session.saveAddress({ name: "adderInShard1", address: addressInShard1 }); | ||
}); | ||
|
||
async function deploy(deployer: ITestUser): Promise<IAddress> { | ||
let interactor = await createAdderInteractor(session); | ||
let { address, returnCode } = await interactor.deploy(deployer, 42); | ||
assert.isTrue(returnCode.isSuccess()); | ||
return address; | ||
} | ||
|
||
it("execute many", async function () { | ||
this.timeout(FiveMinutesInMilliseconds); | ||
|
||
await session.syncUsers([alice, bob]); | ||
|
||
const adderInShard0 = await session.loadAddress("adderInShard0"); | ||
const interactor0 = await createAdderInteractor(session, adderInShard0); | ||
|
||
const transactions: ITransaction[] = []; | ||
|
||
for (let i = 0; i < 10; i++) { | ||
transactions.push(await interactor0.buildTransactionAdd(alice, 1, 30000000)); | ||
} | ||
|
||
await sendTransactions(transactions); | ||
}); | ||
|
||
async function sendTransactions(transactions: ITransaction[]): Promise<void> { | ||
const sendableTransactions = transactions.map(item => item.toSendable()); | ||
const response = await networkProvider.doPostGeneric("transaction/send-multiple", sendableTransactions); | ||
console.log("Sent transactions:", response.numOfSentTxs); | ||
console.log(response); | ||
} | ||
}); |
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,24 @@ | ||
package components | ||
|
||
import ( | ||
"github.com/ElrondNetwork/elrond-proxy-go/data" | ||
) | ||
|
||
// DisabledExternalStorageConnector is a no-operation external storage connector | ||
type DisabledExternalStorageConnector struct { | ||
} | ||
|
||
// GetTransactionsByAddress returns nothing | ||
func (connector *DisabledExternalStorageConnector) GetTransactionsByAddress(address string) ([]data.DatabaseTransaction, error) { | ||
return make([]data.DatabaseTransaction, 0), nil | ||
} | ||
|
||
// GetAtlasBlockByShardIDAndNonce returns nothing | ||
func (connector *DisabledExternalStorageConnector) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { | ||
return data.AtlasBlock{}, nil | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (connector *DisabledExternalStorageConnector) IsInterfaceNil() bool { | ||
return connector == nil | ||
} |
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,13 @@ | ||
package components | ||
|
||
import ( | ||
"github.com/ElrondNetwork/elrond-proxy-go/facade" | ||
"github.com/ElrondNetwork/elrond-proxy-go/process" | ||
) | ||
|
||
// ObserverFacade holds (embeds) several components implemented in elrond-proxy-go | ||
type ObserverFacade struct { | ||
process.Processor | ||
facade.TransactionProcessor | ||
facade.BlockProcessor | ||
} |
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,34 @@ | ||
package factory | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ElrondNetwork/elrond-go-core/data/transaction" | ||
"github.com/ElrondNetwork/elrond-proxy-go/data" | ||
"github.com/ElrondNetwork/rosetta/server/resources" | ||
) | ||
|
||
type networkProvider interface { | ||
IsOffline() bool | ||
GetBlockchainName() string | ||
GetChainID() string | ||
GetNativeCurrency() resources.NativeCurrency | ||
GetObserverPubkey() string | ||
GetNetworkConfig() *resources.NetworkConfig | ||
GetGenesisBlockSummary() *resources.BlockSummary | ||
GetGenesisTimestamp() int64 | ||
GetGenesisBalances() ([]*resources.GenesisBalance, error) | ||
GetLatestBlockSummary() (*resources.BlockSummary, error) | ||
GetBlockByNonce(nonce uint64) (*data.Block, error) | ||
GetBlockByHash(hash string) (*data.Block, error) | ||
GetAccount(address string) (*data.AccountModel, error) | ||
IsAddressObserved(address string) (bool, error) | ||
ConvertPubKeyToAddress(pubkey []byte) string | ||
ConvertAddressToPubKey(address string) ([]byte, error) | ||
SendTransaction(tx *data.Transaction) (string, error) | ||
ComputeTransactionHash(tx *data.Transaction) (string, error) | ||
ComputeReceiptHash(apiReceipt *transaction.ApiReceipt) (string, error) | ||
ComputeTransactionFeeForMoveBalance(tx *data.FullTransaction) *big.Int | ||
GetMempoolTransactionByHash(hash string) (*data.FullTransaction, error) | ||
LogDescription() | ||
} |
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,5 @@ | ||
package factory | ||
|
||
import logger "github.com/ElrondNetwork/elrond-go-logger" | ||
|
||
var log = logger.GetOrCreate("server/factory") |
Oops, something went wrong.