Skip to content

Commit

Permalink
Merge pull request #185 from AElfProject/feature/test-headers
Browse files Browse the repository at this point in the history
Feature/test headers
  • Loading branch information
hzz780 authored Aug 21, 2024
2 parents 7fdc987 + e7d8303 commit a921109
Show file tree
Hide file tree
Showing 4 changed files with 539 additions and 52 deletions.
86 changes: 39 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
</a>
</p>

| Branch | Tests | Coverage |
|--------------|-----------------|----------------|
| Branch | Tests | Coverage |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| `feature/test-chain-util` | ![Tests](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/AElfProject/aelf-web3.js/feature/badge-json/feature-test-chain-util-test-results.json) | ![Coverage](https://AElfProject.github.io/aelf-web3.js/badges.svg) |

<!-- | Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](https://img.shields.io/badge/statements-97.98%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-95.49%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-98%25-brightgreen.svg?style=flat) | -->

| ![Statements](https://img.shields.io/badge/statements-97.98%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-95.3%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-98%25-brightgreen.svg?style=flat) | -->

## 1. Introduction

Expand Down Expand Up @@ -80,9 +79,9 @@ module.exports = {
// ...
resolve: {
alias: {
'aelf-sdk$': 'aelf-sdk/dist/aelf.umd.js',
},
},
'aelf-sdk$': 'aelf-sdk/dist/aelf.umd.js'
}
}
};
```

Expand All @@ -95,9 +94,9 @@ rollup({
// ...
plugins: [
alias({
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.umd.js'),
}),
],
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.umd.js')
})
]
});
```

Expand All @@ -110,9 +109,9 @@ module.exports = {
// ...
resolve: {
alias: {
'aelf-sdk$': 'aelf-sdk/dist/aelf.cjs.js',
},
},
'aelf-sdk$': 'aelf-sdk/dist/aelf.cjs.js'
}
}
};
```

Expand All @@ -125,9 +124,9 @@ rollup({
// ...
plugins: [
alias({
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.cjs.js'),
}),
],
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.cjs.js')
})
]
});
```

Expand All @@ -143,9 +142,7 @@ You can also see full examples in [./examples](./examples);
import AElf from 'aelf-sdk';

// create a new instance of AElf
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:1235')
);
const aelf = new AElf(new AElf.providers.HttpProvider('http://127.0.0.1:1235'));
```

2. Create or load a wallet with `AElf.wallet`
Expand All @@ -170,14 +167,9 @@ You can also see full examples in [./examples](./examples);
// get genesis contract address
const GenesisContractAddress = chainStatus.GenesisContractAddress;
// get genesis contract instance
const zeroContract = await aelf.chain.contractAt(
GenesisContractAddress,
newWallet
);
const zeroContract = await aelf.chain.contractAt(GenesisContractAddress, newWallet);
// Get contract address by the read only method `GetContractAddressByName` of genesis contract
tokenContractAddress = await zeroContract.GetContractAddressByName.call(
AElf.utils.sha256(tokenContractName)
);
tokenContractAddress = await zeroContract.GetContractAddressByName.call(AElf.utils.sha256(tokenContractName));
})();
```

Expand All @@ -193,7 +185,7 @@ You can also see full examples in [./examples](./examples);
})();

// promise way
aelf.chain.contractAt(tokenContractAddress, wallet).then((result) => {
aelf.chain.contractAt(tokenContractAddress, wallet).then(result => {
tokenContract = result;
});

Expand All @@ -215,7 +207,7 @@ You can also see full examples in [./examples](./examples);
// with `.call` method, `aelf-sdk` will only call read-only method
const result = await tokenContract.GetBalance.call({
symbol: 'ELF',
owner: '7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz',
owner: '7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz'
});
console.log(result);
/**
Expand All @@ -230,7 +222,7 @@ You can also see full examples in [./examples](./examples);
symbol: 'ELF',
to: '7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz',
amount: '1000000000',
memo: 'transfer in demo',
memo: 'transfer in demo'
});
console.log(transactionId);
/**
Expand All @@ -246,9 +238,7 @@ You can also see full examples in [./examples](./examples);
```javascript
import AElf from 'aelf-sdk';

const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:1235')
);
const aelf = new AElf(new AElf.providers.HttpProvider('http://127.0.0.1:1235'));
aelf.setProvider(new AElf.providers.HttpProvider('http://127.0.0.1:8000'));
```

Expand Down Expand Up @@ -299,7 +289,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getChainStatus().then((res) => {
aelf.chain.getChainStatus().then(res => {
console.log(res);
});
```
Expand All @@ -323,7 +313,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getContractFileDescriptorSet(contractAddress).then((res) => {
aelf.chain.getContractFileDescriptorSet(contractAddress).then(res => {
console.log(res);
});
```
Expand All @@ -347,7 +337,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getBlockHeight().then((res) => {
aelf.chain.getBlockHeight().then(res => {
console.log(res);
});
```
Expand Down Expand Up @@ -391,7 +381,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getBlock(blockHash, false).then((res) => {
aelf.chain.getBlock(blockHash, false).then(res => {
console.log(res);
});
```
Expand Down Expand Up @@ -435,7 +425,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getBlockByHeight(12, false).then((res) => {
aelf.chain.getBlockByHeight(12, false).then(res => {
console.log(res);
});
```
Expand Down Expand Up @@ -479,7 +469,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getTxResult(transactionId).then((res) => {
aelf.chain.getTxResult(transactionId).then(res => {
console.log(res);
});
```
Expand All @@ -506,7 +496,7 @@ _Returns_
_Example_

```javascript
aelf.chain.getTxResults(blockHash, 0, 2).then((res) => {
aelf.chain.getTxResults(blockHash, 0, 2).then(res => {
console.log(res);
});
```
Expand Down Expand Up @@ -594,7 +584,7 @@ you need to create a aelf authorization instance and set a provider
```javascript
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('UseName', 'Password'),
Authorization: AElf.utils.getAuthorization('UseName', 'Password')
})
);
```
Expand All @@ -604,11 +594,11 @@ _Example_
```javascript
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('aelf', '12345678'),
Authorization: AElf.utils.getAuthorization('aelf', '12345678')
})
);

aelf.chain.addPeer('192.168.11.140:6801').then((res) => {
aelf.chain.addPeer('192.168.11.140:6801').then(res => {
console.log(res);
});
```
Expand All @@ -622,7 +612,7 @@ you need to create a aelf authorization instance and set a provider
```javascript
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('UseName', 'Password'),
Authorization: AElf.utils.getAuthorization('UseName', 'Password')
})
);
```
Expand All @@ -632,11 +622,11 @@ _Example_
```javascript
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('aelf', '12345678'),
Authorization: AElf.utils.getAuthorization('aelf', '12345678')
})
);

aelf.chain.removePeer('192.168.11.140:6801').then((res) => {
aelf.chain.removePeer('192.168.11.140:6801').then(res => {
console.log(res);
});
```
Expand Down Expand Up @@ -792,8 +782,9 @@ AElf.version; // eg. 3.2.23
![node](https://img.shields.io/badge/node->=10-green.svg)

## 4. Building
- [Node.js](https://nodejs.org)
- [npm](https://www.npmjs.com/)

- [Node.js](https://nodejs.org)
- [npm](https://www.npmjs.com/)

```bash
sudo apt-get update
Expand All @@ -816,6 +807,7 @@ yarn run test
```

Commit code will run test and lint automatically, and show the test result in readme.md, please make sure all test cases passed.

### 4.3 About contributing

Read out [contributing guide](./.github/CONTRIBUTING.md)
Expand Down
Loading

0 comments on commit a921109

Please sign in to comment.