Skip to content

Commit

Permalink
Merge pull request #43 from stellar/459/fix-for-source-alias
Browse files Browse the repository at this point in the history
Update system tests for `--source-account` flag
  • Loading branch information
paulbellamy authored Mar 13, 2023
2 parents ea24ecd + 8872c9a commit 28e5ef1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions features/dapp_develop/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (

// return the fn response as a serialized string
// uses secret-key and network-passphrase directly on command
func invokeContractFromCliTool(deployedContractId string, contractName string, functionName string, param1 string, e2eConfig *e2e.E2EConfig) (string, error) {
func invokeContractFromCliTool(deployedContractId, contractName, functionName, param1 string, e2eConfig *e2e.E2EConfig) (string, error) {
args := []string{
"contract",
"invoke",
"--id", deployedContractId,
"--rpc-url", e2eConfig.TargetNetworkRPCURL,
"--secret-key", e2eConfig.TargetNetworkSecretKey,
"--source", e2eConfig.TargetNetworkSecretKey,
"--network-passphrase", e2eConfig.TargetNetworkPassPhrase,
"--",
functionName,
Expand All @@ -44,12 +44,12 @@ func invokeContractFromCliTool(deployedContractId string, contractName string, f
}

// invokes the contract using identities and network from prior setup of config state in cli
func invokeContractFromCliToolWithConfig(deployedContractId string, contractName string, functionName string, parameters string, identity string, networkConfig string, e2eConfig *e2e.E2EConfig) (string, error) {
func invokeContractFromCliToolWithConfig(deployedContractId, contractName, functionName, parameters, identity, networkConfig string, e2eConfig *e2e.E2EConfig) (string, error) {
args := []string{
"contract",
"invoke",
"--id", deployedContractId,
"--identity", identity,
"--source", identity,
"--network", networkConfig,
"--",
functionName,
Expand Down
6 changes: 3 additions & 3 deletions features/dapp_develop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func deployContract(compiledContractFileName string, contractWorkingDirectory st
"deploy",
"--wasm-hash", installedContractId,
"--rpc-url", e2eConfig.TargetNetworkRPCURL,
"--secret-key", e2eConfig.TargetNetworkSecretKey,
"--source", e2eConfig.TargetNetworkSecretKey,
"--network-passphrase", e2eConfig.TargetNetworkPassPhrase)
} else {
envCmd = cmd.NewCmd("soroban",
"contract",
"deploy",
"--wasm", fmt.Sprintf("./%s/target/wasm32-unknown-unknown/release/%s", contractWorkingDirectory, compiledContractFileName),
"--rpc-url", e2eConfig.TargetNetworkRPCURL,
"--secret-key", e2eConfig.TargetNetworkSecretKey,
"--source", e2eConfig.TargetNetworkSecretKey,
"--network-passphrase", e2eConfig.TargetNetworkPassPhrase)
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func installContract(compiledContractFileName string, contractWorkingDirectory s
"install",
"--wasm", fmt.Sprintf("./%s/target/wasm32-unknown-unknown/release/%s", contractWorkingDirectory, compiledContractFileName),
"--rpc-url", e2eConfig.TargetNetworkRPCURL,
"--secret-key", e2eConfig.TargetNetworkSecretKey,
"--source", e2eConfig.TargetNetworkSecretKey,
"--network-passphrase", e2eConfig.TargetNetworkPassPhrase)

status, stdOut, err := e2e.RunCommand(envCmd, e2eConfig)
Expand Down
5 changes: 2 additions & 3 deletions features/dapp_develop/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func invokeContractFromNodeJSTool(deployedContractId, contractName, functionName
"--",
"--id", deployedContractId,
"--rpc-url", e2eConfig.TargetNetworkRPCURL,
"--account", e2eConfig.TargetNetworkPublicKey,
"--secret-key", e2eConfig.TargetNetworkSecretKey,
"--source", e2eConfig.TargetNetworkSecretKey,
"--network-passphrase", e2eConfig.TargetNetworkPassPhrase,
"--fn", functionName,
}
Expand All @@ -42,6 +41,6 @@ func invokeContractFromNodeJSTool(deployedContractId, contractName, functionName
}

// invokes the contract using identities and network from prior setup of config state in cli
func invokeContractFromNodeJSToolWithConfig(deployedContractId string, contractName string, functionName string, parameters string, identity string, networkConfig string, e2eConfig *e2e.E2EConfig) (string, error) {
func invokeContractFromNodeJSToolWithConfig(deployedContractId, contractName, functionName, parameters, identity, networkConfig string, e2eConfig *e2e.E2EConfig) (string, error) {
return "", fmt.Errorf("invoke with named identity not supported for NODEJS tool")
}
14 changes: 7 additions & 7 deletions invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ async function main() {

parser.add_argument('--id', { dest: 'contractId', required: true, help: 'Contract ID' });
parser.add_argument('--rpc-url', { dest: 'rpcUrl', required: true, help: 'RPC URL' });
parser.add_argument('--account', { dest: 'account', required: true, help: 'Account ID' });
parser.add_argument('--secret-key', { dest: 'secretKey', required: true, help: 'Secret key' });
parser.add_argument('--source', { dest: 'source', required: true, help: 'Secret key' });
parser.add_argument('--network-passphrase', { dest: 'networkPassphrase', required: true, help: 'Network passphrase' });
parser.add_argument('--fn', { dest: 'functionName', required: true, help: 'Function name' });
parser.add_argument('--param1', { dest: 'param1', help: 'Param 1' });

const {
contractId,
rpcUrl,
account,
param1,
networkPassphrase,
secretKey,
source,
functionName,
} = parser.parse_args() as Record<string, string>;

const contract = new SorobanClient.Contract(contractId);
const server = new SorobanClient.Server(rpcUrl, { allowHttp: true });
const source = await server.getAccount(account)
const secretKey = SorobanClient.Keypair.fromSecret(source);
const account = secretKey.publicKey();
const sourceAccount = await server.getAccount(account);

// Some hacky param-parsing. Generated Typescript bindings would be better
// here. But those don't exist yet as I'm writing this.
const params = param1 ? [xdr.ScVal.scvSymbol(param1)] : [];

const txn = await server.prepareTransaction(
new SorobanClient.TransactionBuilder(source, {
new SorobanClient.TransactionBuilder(sourceAccount, {
fee: "100",
networkPassphrase,
})
Expand All @@ -42,7 +42,7 @@ async function main() {
networkPassphrase
);

txn.sign(SorobanClient.Keypair.fromSecret(secretKey));
txn.sign(secretKey);
const send = await server.sendTransaction(txn);
if (send.errorResultXdr) {
throw new Error(`Transaction failed: ${JSON.stringify(send)}`);
Expand Down

0 comments on commit 28e5ef1

Please sign in to comment.