Skip to content

Commit

Permalink
Clean up some style nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Nov 16, 2020
1 parent 1ca2e29 commit f072e8c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bridge/pkg/processor/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func (p *Processor) handleObservation(ctx context.Context, m *gossipv1.LockupObs
zap.Any("vaa", signed),
zap.String("bytes", hex.EncodeToString(vaaBytes)))

// Check whether we run in devmode and submit the VAA ourselves, if so.
switch t.TargetChain {
case vaa.ChainIDEthereum:
// Check whether we run in devmode and submit the VAA ourselves, if so.
p.devnetVAASubmission(ctx, signed, hash)
case vaa.ChainIDTerra:
p.terraVAASubmission(ctx, signed, hash)
Expand Down Expand Up @@ -199,7 +199,7 @@ func (p *Processor) devnetVAASubmission(ctx context.Context, signed *vaa.VAA, ha
}
}

// Submit VAA to Terra
// Submit VAA to Terra devnet.
func (p *Processor) terraVAASubmission(ctx context.Context, signed *vaa.VAA, hash string) {
tx, err := terra.SubmitVAA(ctx, p.terraLCD, p.terraChaidID, p.terraContract, p.terraFeePayer, signed)
if err != nil {
Expand Down
18 changes: 10 additions & 8 deletions bridge/pkg/terra/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
if err != nil {
return fmt.Errorf("event subscription failed: %w", err)
}
logger.Info("Subscribed to new transaction events")
logger.Info("subscribed to new transaction events")

go func() {
defer close(errC)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
if targetChain.Exists() && tokenChain.Exists() && tokenDecimals.Exists() && token.Exists() &&
sender.Exists() && recipient.Exists() && amount.Exists() && amount.Exists() && nonce.Exists() && txHash.Exists() {

logger.Info("Token lock detected on Terra: ",
logger.Info("token lock detected on Terra",
zap.String("txHash", txHash.String()),
zap.String("targetChain", targetChain.String()),
zap.String("tokenChain", tokenChain.String()),
Expand All @@ -119,22 +119,22 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {

senderAddress, err := StringToAddress(sender.String())
if err != nil {
logger.Error("cannot decode hex ", zap.String("value", sender.String()))
logger.Error("cannot decode hex", zap.String("value", sender.String()))
continue
}
recipientAddress, err := StringToAddress(recipient.String())
if err != nil {
logger.Error("cannot decode hex ", zap.String("value", recipient.String()))
logger.Error("cannot decode hex", zap.String("value", recipient.String()))
continue
}
tokenAddress, err := StringToAddress(token.String())
if err != nil {
logger.Error("cannot decode hex ", zap.String("value", token.String()))
logger.Error("cannot decode hex", zap.String("value", token.String()))
continue
}
txHashValue, err := StringToHash(txHash.String())
if err != nil {
logger.Error("cannot decode hex ", zap.String("value", txHash.String()))
logger.Error("cannot decode hex", zap.String("value", txHash.String()))
continue
}
lock := &common.ChainLock{
Expand All @@ -161,6 +161,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
errC <- err
return
}

client := &http.Client{
Timeout: time.Second * 15,
}
Expand All @@ -178,17 +179,18 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
resp.Body.Close()
return
}

json = string(body)
guardianSetIndex := gjson.Get(json, "result.guardian_set_index")
addresses := gjson.Get(json, "result.addresses.#.bytes")

logger.Debug("Current guardian set on Terra: ",
logger.Debug("current guardian set on Terra",
zap.Any("guardianSetIndex", guardianSetIndex),
zap.Any("addresses", addresses))

resp.Body.Close()

// Do not report it since ETH guardians are the source of truth
// We do not send guardian changes to the processor - ETH guardians are the source of truth.
}
}()

Expand Down
2 changes: 2 additions & 0 deletions bridge/pkg/vaa/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (c ChainID) String() string {
return "solana"
case ChainIDEthereum:
return "ethereum"
case ChainIDTerra:
return "terra"
default:
return fmt.Sprintf("unknown chain ID: %d", c)
}
Expand Down
13 changes: 9 additions & 4 deletions terra/docs/testing.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# Wormhole + Terra local test environment

For the list of dependencies please follow [DEVELOP.md](../../DEVELOP.md)
For the list of dependencies please follow [DEVELOP.md](../../DEVELOP.md).

Additional dependencies:
- [Node.js](https://nodejs.org/) >= 14.x, [ts-node](https://www.npmjs.com/package/ts-node) >= 8.x

Start Tilt from the project root:

tilt up
tilt up --update-mode=exec -- --num=1

Afterwards use test scripts in `terra/tools` folder:

npm install
npm run prepare-token
npm run prepare-wormhole

These commands will give you two important addresses: test token address and Wormhole contract address on Terra. Now you need to change guardian configuration to monitor the right contract. Copy Wormhole contract address and replace existing address in file `devnet/bridge-terra.yaml` (line 67). Save the changes and monitor Tilt dashboard until guardian services restart.
These commands will give you two important addresses: test token address and Wormhole contract address on Terra.
Now you need to change guardian configuration to monitor the right contract. Copy Wormhole contract address and
replace existing `TERRA_FEE_PAYER` address in `devnet/bridge.yaml`.

Save the changes and monitor Tilt dashboard until guardian services restart.

Now use both token address and Wormhole contract address to issue tocken lock transaction:

npm run lock-tocken -- TOKEN_CONTRACT WORMHOLE_CONTRACT 1000

Where 1000 is a sample amount to transfer. After this command is issued monitor Guardian service in Tilt dashboard to see its effects propagated to the destination blockchain (in this case it is Ethereum).
Where 1000 is a sample amount to transfer. After this command is issued monitor Guardian service in Tilt dashboard
to see its effects propagated to the destination blockchain (in this case it is Ethereum).
5 changes: 3 additions & 2 deletions terra/tools/prepare-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { deploy_contract, instantiate_contract, query_contract } from './utils';

async function script() {
const TEST_ADDRESS: string = 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v';
// cw20_base.wasm is build from https://github.com/CosmWasm/cosmwasm-plus repository, v.0.2.0 and is a standard base cw20 contract
// cw20_base.wasm is a binary artifact built from https://github.com/CosmWasm/cosmwasm-plus repository at v0.2.0
// and is a standard base cw20 contract. Is it used for testing only.
let code_id = await deploy_contract('../artifacts/cw20_base.wasm');
if (code_id == -1) return;
console.log(`Program deployed with code id ${code_id}`);
Expand All @@ -23,4 +24,4 @@ async function script() {
console.log(`${TEST_ADDRESS} balance is ${result.balance}`);
}

script();
script();

0 comments on commit f072e8c

Please sign in to comment.